DEV Community

Cover image for Plot with python (matplotlib, seaborn)
bluepaperbirds
bluepaperbirds

Posted on

Plot with python (matplotlib, seaborn)

Do you want to make beautiful charts with Python? You can with matplotlib or seaborn.

Matplotlib is a plotting library for the Python programming language. It lets you create charts like a bar chart, line chart and many other basic charts.

Seaborn is a Python data visualization library based on matplotlib.It provides a high-level interface for drawing attractive and informative statistical graphics.

You should know the basics of Python before trying to make plots.

Example

So is it complicated to make a plot? It depends. Creating a plot can be as simple as 3 lines of code:

import matplotlib.pyplot as plt

plt.bar([1,2,3,4,5], [10,20,30,40,50])
plt.show()

where it's x-values and y-values in the bar parameters. This shows a simple bar chart:

bar chart

Now that is with matplotlib alone. What about seaborn?

With seaborn you can change the colors, add a grid etc. There are also many other plots. You'll see seaborn looks a lot more modern:

import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style="darkgrid")

plt.bar([1,2,3,4,5], [10,20,30,40,50], color="m")
plt.title("seaborn")
plt.show()

seaborn plot

You can learn both modules, and because seaborn is based on matplotlib, there isn't much of a difference in learning curve.

Related links:

Top comments (0)