Learn how to use styles in matplotlib to generate better looking graphs. You can see how to find the available styles and look into a gallery of all styles.
- [Instructor] Let's start with a basic chart and see how we can customize it to make it look better. Of course, beauty is in the eye of the beholder and I usually get someone with a good sense of aesthetics to give me an opinion before I publish a report. We'll open a new notebook from the New, Python 3 and then let's name it Style. When you work in a Jupyter notebook, we need to tell matplotlib to draw in the notebook. We do this with a percent matplotlib inline magic. If you float something and it doesn't show in the notebook, it probably means that you forgot to write the matplotlib inline magic.
If you forgot, you'll probably have to add the magic line and then reload the notebook or even restart the canal. Now let's import pandas and NumPy and generate some data. So import numpy as np We import pandas as pd, and then we say that the x's is numpy linear space from minus six to six and a hundred points. And the y's is numpy the sinc function of the xs.
Now let's operate a data frame from this data, we'll say the data frame is pandas.dataframe. And this time we're going to pass dictionary, saying x is the x's, and sinc is the y's. And let's plot it. So dataframe plot, line plot, where the x is x, and the y is the sinc. We have our chart, and it looks okay. Matplotlib 2.0 improved the different style, so things look good right off the bat.
Now sometimes, we like to get a different look. We need to import matplotlib to use styles. Most of the time, we import the pyplot submodel, so let's do that. Import matplotlib.pyplot as plt. We have several styles available for us. Plt.style.available. See several of them. Let's pick one, and do the same plot. So we'll tell plt.style to use the seaborn white grid style.
And then we'll plot again. Df.plot.line, x equal x, and y equal sinc. Now we have gridlines, which are useful to see where internal points are. Let's try another style. Plt.style.use 538. And then again, df.plot.line where x is x and y is the sinc. And now we have a totally different style, the lines are thicker, it's gray.
I encourage you to try it, a few styles, to see which one you like best For a quick overview, you can head over to the style gallery and check them out. If none of the styles fits your need, you can create your own. This is a bit involved, but is documented well at the matplotlib website.
- Working with Jupyter notebooks
- Using code cells
- Extensions to the Python language
- Markdown cells
- Editing notebooks
- NumPy basics
- Broadcasting, array operations, and ufuncs
- Folium and Geo
- Machine learning with scikit-learn
- Plotting with matplotlib and bokeh
- Branching into Numba, Cython, deep learning, and NLP
Skill Level Intermediate
NumPy Data Science Essential Trainingwith Charles Kelly3h 54m Intermediate
1. Scientific Python Overview
2. The Jupyter Notebook
3. NumPy Basics
Manage environments5m 11s
6. Folium and Geo
7. NY Taxi Data
10. Other Packages
11. Development Process
Next steps1m 33s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.