Matplotlib > Linear plots

Name
Code
Output
x = [0,1,2,3,4]
y = [1,2,3,2,3]
matplotlib.pyplot.plot(x, y)
matplotlib.pyplot.show()

       
           Linear plot (basic)
       
    
# Data
x = numpy.linspace(0,4,10)
y1 = x
y2 = x**2
# 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.plot(x,y1,color='blue', linestyle='dashed', marker='o',
     markerfacecolor='orange', markersize=10)
ax.plot(x,y2,color='red', linestyle='dashed', marker='o',
     markerfacecolor='silver', markersize=10)
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()

       
           Linear plot (customized)