Visualization Libraries for Python

AE
AE
Mar 24 · 3 min read
Image from Real Python’s Guide (https://realpython.com/python-matplotlib-guide/)

This is an introductory look at some visualization libraries for Python. When you first start visualizing your data (plotting) in Python, you probably will import the MatPlotLib (plt) library. It’s a great library that allows you to plot in many situations (like with Pandas) and gives great functionality to the plotting layout, tick marks, and labels. I’d like to introduce a few other plotting libraries that take plt to new levels with more options for color and functionality (3D / interactive). You can technically do most of these things through MatPlotLib, with added tool kits and functions within its library and a few more lines of code, but sometimes other libraries make it easier. If you want to read more into MatPlotLib plotting their [documentation] is extensive and they provide great [tutorials] for introductory to more advanced plotting. Real Python provides a great breakdown of the notation used to really get a grasp of the parameters.


Seaborn

The first library to utilize is Seaborn (sns()), a “statistical data visualization. Seaborn is a Python data visualization library based on MatPlotLib. It provides a high-level interface for drawing attractive and informative statistical graphics.” Its functions make it easy to create various plots that are more aesthetically appealing than MatPlotLib, and it’s more straightforward to plot categorical data from a Pandas data frame. The Seaborn documentation provides extensive visualization examples and tutorials so I won’t go through them here. Violin plots and heatmaps are just a couple that make Seaborn stand out compared to standalone MatPlotLib, being able to plot them in just two simple lines of code.

Seaborn Heatmap Showing Number of Passengers by Month and Year

Bokeh

This library gives the ability to become more interactive with plots and is described by their team as, “an interactive visualization library that targets modern web browsers for presentation”. The coding here is a bit more extensive as you have to apply many functions to create an interactive plot, but again it is still easier than creating interactivity with matplotlib (most of the time). The Bokeh documentation has user guides, a gallery of examples, and they even have a section for tutorials that opens in its own Jupyter Notebook.

Interaction from Real Python’s Bokeh Guide (realpython.com/python-data-visualization-bokeh/)

Plot.ly

This is a great interactive plotting library that allows you to easily export plots as images, and has code to create interactive environments both within Jupyter Notebooks and standalone in web pages (HTML). Since Plotly’s focus is dashboarding, it’s aesthetically pleasing and second to none for user interaction. For anyone looking to combine geographical maps and heatmaps, this is your tool. They’re called choropleth maps and you can use coordinates or names (cities, states, countries), then Plot.ly can easily create the choropleth plot. Plotly can also be used to create interactive 3D plots which can be useful for heavily clustered data to easily view from other angles a 2D map simply cannot provide. Their documentation is great providing a cheatsheet and great examples, which is especially useful for those who may be plotting offline.

Plotly Jupyter Notebook Tutorial

Additional Resources

There are many ways to visualize data in Python for data science, so I hope this gave you an idea of what you can do. Besides looking at documentation and the provided examples, I also suggest looking at The Python Graph Gallery, which organizes plots by types and typically gives examples of different libraries to create those visualizations with. There are other visualization libraries out there and all of them have the capability to create amazing, concise, and easy to follow plots. Happy visualizing!

1

1 clap
AE

Written by

AE

A data scientist taking tiny bytes