Plotting one curve
The initial example of Hello World! for a plotting software is often about showing a simple curve. We will keep up with that tradition. It will also give you a rough idea about how matplotlib works.
Getting ready
You need to have Python (either v2.7 or v3) and matplotlib installed. You also need to have a text editor (any text editor will do) and a command terminal to type and run commands.
How to do it...
Let's get started with one of the most common and basic graph that any plotting software offers—curves. In a text file saved as plot.py
, we have the following code:
import matplotlib.pyplot as plt X = range(100) Y = [value ** 2 for value in X] plt.plot(X, Y) plt.show()
Tip
Downloading the example code
You can download the sample code ...
Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.