Legacy – Basic Chart Straight Line Workout
- 01:49
Workout demonstrating how to create a basic straight line chart in Python
Glossary
Matplotlib Straight line ChartTranscript
Let us now start to plot some charts in Python. Before we do anything to basic procedure, we've got to import matplotlib Pyplot as plt. Then, let's try to plot a straight line first, because let's start from the basics. So let's assume we've got five points 1, 2, 3, 4, 5, I'm going to plot it simple. Just like for a numpy array, we need to do NumPy . array or for pandas, we need to do pd . series in a similar way, in order to plot it using the matplotlib library. We've got to say pl, . plot. And now we need to define the points that we want to plot. So like I said, if we want to plot five points, a list of 1, 2, 3, 4 and five, let's run this perfect, no error return, meaning it's good. But why couldn't we see the plot? Because whenever you brought something at the end, you've got to say PLT, dot show, meaning you wanted to show the plot. Perfect, that's running. And this is the plot of straight line. In order to save the plot, we need to select the option over here and you can save it as a png. But how do we get a y label? We can say plt dot y label and in brackets and in quotations, we can say numbers. And we run this again. We can see that the y axis has a label of numbers. Perfect