create a matplotlib plot in python

First you need to install matplotlib package through pip command. In command prompt type pip install matplotlib. Then you can create a plot using the following code:

main.py
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [10, 5, 8, 4, 3, 2, 8, 7, 11]

plt.plot(x, y) # create plot
plt.xlabel('X Label') # set x-axis label
plt.ylabel('Y Label') # set y-axis label
plt.title('Title') # set plot title
plt.show() # show plot
270 chars
11 lines

This code creates a simple line plot of x and y. plt.xlabel(), plt.ylabel(), and plt.title() functions are used to label the axes and set a title to the plot. Finally, plt.show() function is used to display the plot.

gistlibby LogSnag