s

Data visualisation with Python

By Angela C

March 2, 2021 in matplotlib seaborn altair plotly

Reading time: 4 minutes.

There are many plotting libraries available for visualising data with Python starting with Matplotlib which is the foundation for many other plotting libraries in Python such as Seaborn, Pandas and GeoPandas. There are also JavaScript-based libraries such as Bokeh and Plotly and JSON based libraries such as Altair. I have used Matplotlib and Seaborn quite a bit already. I am currently learning Dash / Plotly.

For now I will just down some notes as a reference point. Later I will include some data visualisations from my repositories.

Matplotlib, which is the foundation for most other plotting libraries in Python including built-in plotting functions of pandas and seaborn, allows you to control every single aspect of a figure as well as having multiple plots in single image.

The Matplotlib Pyplot tutorial is probably the best starting point.

Matplotlib based visualisation libraries.

  • pandas is mainly a data analysis and manipulation library but it does have some plotting and visualisation functions based on Matplotlib.

  • GeoPandas is an open source project to make working with geospatial data in python easier. It is an extension to the pandas plotting library for working with geospatial or geographical data.

  • Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. seaborn library adds to matplotlib’s basic functions and allows the user to easily create information and nice looking plots with little lines of code. seaborn abstracts away many of matplotlib's low level functions and methods. Seaborn also allows the user to customise the plot with styles / themes. Seaborn works well with panda's dataframes.

JavaScript based libraries

There are also some javascript-based libraries. Such libraries wrap JavaScript/HTML5 functions and tools in Python and allow the user the create interactive plots.

  • Bokeh is a Python library for creating interactive visualizations for modern web browsers. It helps you build beautiful graphics, ranging from simple plots to complex dashboards with streaming datasets. With Bokeh, you can create JavaScript-powered visualizations without writing any JavaScript yourself. Bokeh is an interactive visualisation library. The interactive visualisations can be displayed in a Jupyter notebook and web browsers. Visualisations in Bokeh use objects called glyphs.

  • Plotly Python Open Source Graphing Library makes interactive, publication-quality graphs. Plotly.py is free and open-source.

The getting started guide outlines how the plotly Python library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases.

Built on top of the Plotly JavaScript library (plotly.js), plotly enables Python users to create beautiful interactive web-based visualizations that can be displayed in Jupyter notebooks, saved to standalone HTML files, or served as part of pure Python-built web applications using Dash. The plotly Python library is sometimes referred to as “plotly.py” to differentiate it from the JavaScript library.

A search for Plotly brings you to the home page of Dash Enterprise at https://plotly.com.

  • dash is a productive Python framework for building web analytic applications.

Written on top of Flask, Plotly.js, and React.js, Dash is ideal for building data visualization apps with highly custom user interfaces in pure Python. It’s particularly suited for anyone who works with data in Python.

Visualisations in Plotly use objects called a trace. Many traces can be combined and displayed in a single figure. Plotly plots can be easily embedded in web pages or exported to different formats such as png, svg, html, pdf etc. Plotly plots can also be created with JSON charts.

JSON based libraries.

  • Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite.

Altair offers a powerful and concise visualization grammar that enables you to build a wide range of statistical visualizations quickly.

Vega is a visualization grammar, a declarative language for creating, saving, and sharing interactive visualization designs. With Vega, you can describe the visual appearance and interactive behavior of a visualization in a JSON format, and generate web-based views using Canvas or SVG.

Altair is a declarative library where the user declares the kind of graph and its features with little code. Altair’s interactive visualisations can be used in Jupyter notebooks.

There are other Python visualisation libraries such as Plotnine which is an implmentation of the grammar of graphics in Python based on the R language’s ggplot2 library.

plotnine is an implementation of a grammar of graphics in Python, it is based on ggplot2. The grammar allows users to compose plots by explicitly mapping data to the visual objects that make up the plot. The grammar allows users to compose plots by explicitly mapping data to the visual objects that make up the plot.

  • Streamlit is an open-source Python library that makes it easy to create and share beautiful, custom web apps for machine learning and data science.

References