Relation

Pandas Dataframe vs. plt.plot

As you have seen, both of these processes produce similar results in the line plot. However, plt.plot is a more itemized way of creating line plots. Stylization choices are more explicit, which makes it easier to see where to change each item, but requires more coding overall.

If ease is preferred over customization, we can choose to use a built-in style of Matplotlib. To see available styles, execute

print(plt.style.available)

This should return a list of strings that can be passed into plt.style.use() to set a style.

Our previous line plot would look like this:

from matplotlib import pyplot as plt plt.style.use('fivethirtyeight') x=[1,2,3,4] y=[1,4,3,2] y_2=[5,4,1,6] plt.plot(x, y, label='Thing One') plt.plot(x, y_2, label='Thing Two') plt.xlabel('Time') plt.ylabel('Number of things') plt.title('Basic Plot') plt.legend() plt.tight_layout() plt.savefig('plt.png') plt.show()

There is a little less work to be done here for a similar result.

Image 0

0

1

Updated 2021-07-12

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science