Creating a simple line plot:
from matplotlib import pyplot
x = [7, 3, 9, 2, 6]
y = [4, 2, 7, 4, 8]
pyplot.plot(x,y)
pyplot.show()
- In the above code, we plotted graph without setting any properties like title, x-axis name, y-axis name
- We can set titles using pre-defined functions of pyplot module
from matplotlib import pyplot as plt
x = [1,2,3]
y = [4,5,1]
plt.plot(x,y)
plt.title("First Graph")
plt.ylabel("y-axis")
plt.xlabel("x-axis")
plt.show()
- If we give only one set of values to generate the graph.
- It plots the x axis range automatically.
- If we provide only 1 list to the plot(), matplotlib assumes it as a sequence of y values and generate x values automatically.
- x axis range starts with 0
from matplotlib import pyplot as plt
data = [10,30,40,70,90]
plt.plot(data)
plt.show()