There's more...

Matplotlib is not the only library we can use to plot histograms. Bokeh (available at https://bokeh.pydata.org/en/latest/) is another powerful plotting library, built on top of D3.js, which allows you to interactively play with your charts.

Check out the gallery of examples at https://bokeh.pydata.org/en/latest/docs/gallery.html.

Here's how you plot with Bokeh:

%%local
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.io import output_notebook
output_notebook()

labels = [str(round(e, 2)) for e in hist_MPG['bins']]

p = figure(
x_range=labels,
plot_height=350,
title='Histogram of fuel economy'
)

p.vbar(x=labels, top=hist_MPG['counts'], width=0.9)

show(p)

First, we load all the necessary components of Bokeh; the output_notebook() method makes sure that we produce the chart inline in the notebook instead of opening a new window each time. Next, we produce the labels to put on our chart. Then, we define our figure: the x_range parameter specifies the number of points on the x axis and the plot_height sets the height of our plot. Finally, we use the .vbar(...) method to draw the bars of our histogram; the x parameter is the labels to put on our plot, and the top parameter specifies the counts. 

The result looks as follows:

It's the same information, but you can interact with this chart in your browser.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset