Matplotlib > Scatter plots

Name
Code
Output
x = numpy.linspace(0,5,20)
y = 2*x
matplotlib.pyplot.scatter(x, y)
matplotlib.pyplot.show()

       
           Scatter plot (basic)
       
    
# Data
x = numpy.linspace(0,4,30)
y1 = x**2
y2 = x**(0.5)
# New Figure
fig = matplotlib.pyplot.figure(figsize=(7,4),facecolor='silver')
# New Axes
ax = fig.add_subplot(111,facecolor='azure')
# Add grid
ax.grid(color='b', linestyle='-', linewidth=0.5)
# set ticks
ax.xaxis.set_ticks(numpy.arange(min(x), max(x)+1, 1.0))
# Plot the data
ax.scatter(x, y1, c='blue', marker='x', linewidths=5)
ax.scatter(x, y2, c='green', marker='o',linewidths=5)
ax.set(title="Plot title", xlabel="x axis", ylabel="y axis")
# Fit the plot layout
matplotlib.pyplot.tight_layout()
# Show the plot
matplotlib.pyplot.show()

       
           Scatter plot (customized)