Plotting in Python With Matplotlib: Simple Line Plots
Published in
2 min readSep 3, 2020
With matplotlib, we can create a bunch of different plots in Python. The most basic plot is the line plot. A general recipe is given here. Try it out yourself here.
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
Lets print out the list of angles on X axis and the sine of x on Y axis.
x=[0, 30, 45, 60, 90]
y=[0, 0.5,1/2**.5,1.732/2, 1]
Output plot:
Plot Title and Axis labelling
- Plot title can be given by command
plt.title( ‘Title of your choosing’ )
2. X axis can be labelled by command
plt.xlabel(‘label of your choosing’)
3. Y axis is labelled by command
plt.ylabel(‘label of your choosing’)
Applying on our problem
plt.title(‘The Sine Curve’)plt.xlabel(‘Angle in degrees’)plt.ylabel(‘Sine of angle’)
Output:
Hopefully this will give you some confidence with plotting line graphs in Python.