edit on Repl.it

Interactive Python Plots

Though the console ony supports text output, we provide with the ability to create plots and charts using matplotlib (and other libraries). Here, we will show you the basics of generating plots using Python3 and matplotlib.

In order to use matplotlib, the first thing you have to do is install the package. Matplotlib is often shortened using as but it does not have to be.

import matplotlib as mpl

Note that this should be in your code as early as possible, and must be before you import the pylab or pyplot packages:

import matplotlib as mpl
import matplotlib.pyplot as plt

Then, write the code to generate the plot as normal. In this example, we're just going to do something simple:


At this point, you would normally use plt.show() to open a new window with the plot, but since that isn't supported, we will have to use plt.savefig() instead. This function saves the plot to an image file.


Running the code should then generate a new pane with your generated plot! The plot has also been saved to an image plot.png. The preview pane will appear whenever the file has been changed.

You can see the above example here. Make sure you drag out the file tree from the left hand side in order to see the newly generated file. To see the generated preview pane, view the repl directly here.