Legacy – Basic Chart Varying Values Workout
- 01:54
Workout demonstrating how to create a Varying Value line chart in Python
Glossary
Matplotlib Varying Value ChartTranscript
When creating the chart in Python, we may sometimes want to assign different values for y and different values for x. In this case, how do we do it? How do we assign two different values. In order to do that, before we do anything, we need to first import the matplotlib library and the Pyplot module. Now, if we want to plot different values for y, or different values for x, we define it. So when we use the plt . plot command, the numbers that go in the first brackets define the x values, and the numbers that go in the second bracket, define the y value. So now we want to say that the x values are 1, 2, 3, 4, and five. Now when defining the y values that can be 1, 3, 5, 9 and 35, the one thing that we need to look at is if the number of values in the list of the y values is the same as the x. So for example, in the first list, if we have five objects, or five items, we need to match that same in the second list. Now we could just run the code. Oh, there's an error. What's there? Well, the error that we did was we've had square brackets even for the Pyplot function. So now we can run it. There shouldn't be any errors returned. Perfect. Now the only thing we need to do is plt . show. And we run it. Excellent. This is a plot. So we define different values for y and different values for x. Perfect