Book Image

Mastering Python for Data Science

By : Samir Madhavan
Book Image

Mastering Python for Data Science

By: Samir Madhavan

Overview of this book

Table of Contents (19 chapters)
Mastering Python for Data Science
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Estimating the Likelihood of Events
Index

Styling your plots


The style package within the matplotlib library makes it easier to change the style of the plots that are being plotted. It is very easy to change to the famous ggplot style of the R language or use the Nate Silver's website http://fivethirtyeight.com/ for fivethirtyeight style. The following example shows the plotting of a simple line chart with the ggplot style:

>>> plt.style.use('ggplot')
>>> plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
>>> plt.show()

After the preceding code is executed we'll get the following output:

In the preceding code, plt.style.use() is used to set the style of the plot. It is a global set, so after it is executed, all the plots that follow will have the same style.

The following code gives the popular fivethirtyeight style, which is Nate Silver's website on data journalism, where his team write articles on various topics by applying data science:

>>> plt.style.use('fivethirtyeight')
>>> plt.plot([1, 2, 3,...