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
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
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
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. This will work regardless
of whether you are in Project Mode or not. 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.