Plot the speed in a box plot using matplotlib. Learn how to display plots inside a Jupyter notebook and how to configure matplotlib to get better looking graphs.
- [Instructor] We can take a quick look at the speed by using the describe method. So, speed1m.describe. This shows some statistics on the speed, but charts are often a better choice. Pandas uses MatPlotLib, which is a plotting library for Python. Let's seen an example. First, we need to tell MatPlotLib to display the charts in our notebook. This is done by writing %matplotlib inline.
Now we can do speed1m.plot. This shows a nice, basic plot. Notice that Pandas knows that the x-axis is time-based. It displays it nicely. If you work directly with MatPlotLib, you'll have to work harder to get such nice results. However, even here, we can make things look a little bit better. Most of the time when I explore data, I plot basic charts. When it's time to present, I invest some effort to make them visually nicer.
It helps with the ability but also makes a better impression. There's no end to how much you can fiddle with your charts. Here are some basic things you can do to improve the visual look of your data. We're going to import matplotlib.pyplot as plt. That's the first imple. And then we can use, we'll do plt.rcParams, and then we say that the figure.figsize, let's say 10 over six.
This will make our charts bigger. Next, we'll say plt.style.use, and then we'll pick a style. I like the seaborn-widegrid style. There are several styles available, and you can pick one that you like most or even design your own. Let's plot again. So, speed1m.plot. Now we get some grid lines and a bigger chart which, in my opinion, is better.
Line charts are one way to display the data. In here you can see the chart nicely visualizes the speed going up and down which is probably related to the hills on my track. Let's do a box plot, which is a quick way to view the range of values. Speed1m.plot.box. You see that my average speed is about 8.5 kilometers per hour with a low at about five and a top of 11 which is probably an outlier. I think that by now we can appreciate how easy to work with data in Panda is.
From reading to calculating to visualization, everything is included.
- 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
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.