December 14, 2019
Matplotlib is a Python library used to create charts and graphs.
from matplotlib import pyplot as plt
x_values = [1,2,3,4]
y_values = [100, 105, 97, 110]
plt.plot(x_values, y_values)
plt.show()
We can also make a line dotted or dashed using the keyword linestyle.
#Dashed
plt.plot(x_values, y_values, linestyle=’—’)
#Dotted
plt.plot(x_values, y_values, linestyle=’:’)
#No line
plt.plot(x_values, y_values, linestyle=’:’)
We can also add a marker using the keyword marker.
#A circle
plt.plot(x_values, y_values, marker=’o’)
#A square
plt.plot(x_values, y_values, marker=’s’)
#A star
plt.plot(x_values, y_values, marker=’*’)
We can change the line color with:
plt.plot(x_values, y_values, color=’#AAAAAA’)
plt.plot(x_values, y_values, color=’green’)