Matplotlib is a library that can be used to create data visualizations.
If you are using replit.com, there is a Python Data Science template that already has pyplot setup with some short example code.
Official documentation for the pyplot portion of matplotlib is here:
https://matplotlib.org/stable/api/pyplot_summary.html
Slightly more complex pyplot examples
There are two systems you can use to create plots using pyplot. Here are two examples that create identical output:
“pyplot” Interface
(The examples on this site use this simpler interface)
import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,2,5]) plt.xlim([0,6]) plt.savefig('example.png')
“fig, ax” Objected Oriented Interface
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1, 2, 3, 4], [1, 4, 2, 5]) ax.set_xlim([0, 6]) plt.savefig('example2.png')
Notice that the functions for setting the limits of the x-axis have different names in the two systems. This is an example of how you can get errors if you mix the two systems.
If you want to understand what’s happening better, this page from the official documents might be very helpful:
https://matplotlib.org/matplotblog/posts/pyplot-vs-object-oriented-interface/
numpy (https://numpy.org/) and n-dimensional arrays
If you dig into pyplot examples, you will find that it makes use of ndarrays, or n-dimensional arrays.
The numpy package is widely used for a variety of math/science/engineering applications, so if you want to make sense of a pyplot example that uses arrays, you might be well served to do a bit of self-studying and experimentation to begin learning how to use numpy.