MITB Banner

A guide to publication-quality data visualization using Proplot

Proplot is a wrapper of the matplotlib library for the visualization of data.
Share

Visualization plays an important role in business analytics and machine learning. Proper visualization of the data helps the business leader and model developer to make their decisions appropriately. Extracting insights from the data requires a huge amount of code and using some of the libraries we can make this insight extraction process very easy. Proplot is also such a library that helps in visualizing data and it is a wrapper of the popular matplotlib library. In this article, we are going to discuss the proplot library and how we can use it to visualize data. The major points to be discussed in the article are listed below.

Table of content 

  1. What is Proplot?
  2. Plots using Proplot.
    1. Creating figure 
    2. Creating subplots   
    3. Creating report

Let’s start with introducing Proplot.

What is Proplot?

Proplot is an open-source python library for the visualization of data and we can also say that it is a wrapper of the matplotlib library. This can help us in making beautiful and ready-to-publish graphs on data. The aim of developing this wrapper is to provide a smoother experience of visualization to the users who are mostly using the matplotlib library. To complete this aim Proplot uses expansion upon matplotlib’s interface that is object-oriented. In this wrapper, we can utilize the changes made by the developer that will be hard to incorporate into matplotlib. 

This library helps us to make graphs in a low code setting which means to make graphs we don’t need to push a lot of codes like we were doing with the matplotlib. As we have discussed above it is a wrapper that means features under this library are a superset of matplotlib and we can use commands from matplotlib like plot, scatter, contour, and pcolor with the proplot package. This wrapper provides two kinds of features 

  • Integration features: In this type of feature this package can use four external packages where pandas and xarray can be used for work on the tables and array and cartopy and basemap are packages for geographic plotting.
  • Additional features: In these features, proplot provides a lot of useful classes and constructor functions that include classes for figure and axis editing, colormap, and cycle constructor.   

In an implementation, we can find that most of the codes we use with proplot are similar to codes we use with matplotlib because the hard dependency of the proplot is matplotlib, and talking about the other soft dependency it uses pandas, Xrray, cartopy, and basemap. We can install this library using the following lines of codes.

!pip install proplot

If any existing old version is already installed in the environment we can upgrade it using the following lines of codes.

!pip install --upgrade proplot

After installing the proplot library we are ready to use it for the visualization of the data. Let’s see some of the examples.

Plots using Proplot

As we know that visualization is mainly required when we try to understand data or we are making reports so in this section we will first go through some of the single graphs and then we will look at how we can make reports like plots using a proplot package.

Creating figure:

Let’s start by making a single figure.

import proplot as pplt
fig = pplt.figure()
ax = fig.subplot()
ax.plot()

Output:

In the above we can see that to make a plot we are using three methods that define the space of the graph then subplot of subplots are responsible for covering information about the graph and the plot method can be used to fill the data inside the graph. Let’s fill this figure.

simple plot using the randomly generated data.

Generating data:  

Generating data:  

import numpy as np
import proplot as pplt
state = np.random.RandomState(51423)
data = 2 * (state.rand(500, 5) - 0.5).cumsum(axis=0)
 
Plotting the data:
 
fig= pplt.figure(suptitle='First Plot')
ax = fig.subplot(xlabel='x', ylabel='y')
ax.plot(data)

Output:

Here we can see the graph with fulfilled data. In the codes, we can see that we have defined the title in the figure function, details of the axis in the subplot function, and data in the plot function. 

Creating subplots:

Let’s see how we can make the subplots in the figure.

import proplot as pplt
fig, axs = pplt.subplots(ncols=2, nrows = 1)
axs.format(color='gray', linewidth=1)

Output:

Here we can see that to make subplots in the figure we have used the subplots function in the figure module and made 2 blank graphs in the figure.

Let’s fill the data in the graphs.  

import numpy as np
import proplot as pplt
state = np.random.RandomState(42)
data1 = 2 * (state.rand(500, 5) - 0.5).cumsum(axis=0)
fig = pplt.figure()
ax = fig.subplot(121)
ax.plot(data1)
ax = fig.subplot(122)
state = np.random.RandomState(42)
data2 = 4 * (state.rand(500, 5) - 0.5).cumsum(axis=0)
ax.plot(data2)
fig.format(
    suptitle='Simple subplot grid', title='Title',
    xlabel='x axis', ylabel='y axis'

Output:

Here we can see that we have filled the data in graphs. 

Creating report 

In the above, we have seen how we can simply make the graphs using the proplot library. In this section, we are going to combine all these to make a report-like visualization. Let’s see how we can do that.   

Let’s make a sample data

state = np.random.RandomState(51423)
data = 4 * (state.rand(40) - 0.5)

Defining figure: 

pplt.rc.abc = 'a.'
pplt.rc.titleloc = 'l'
fig, axs = pplt.subplots(nrows=3, refaspect=2, figwidth=5)
axs.format(
    xmargin=0, xlabel='xlabel', ylabel='ylabel', grid=True,
    suptitle='color differenciation using bar plots',
)
for ax in axs:
    ax.axhline(0, color='k', linewidth=1)

Plotting graphs in the figure:

# Bar plot
ax = axs[0]
ax.bar(data, width=2, negpos=True, edgecolor='B')
ax.format(title='Bar plot')
 
# Area plot
ax = axs[1]
ax.area(data, negpos=True, edgecolor='B')
ax.format(title='Area plot')
 
# Line plot
ax = axs[2]
ax.vlines(data, linewidth=1, negpos=True)
ax.format(title='Line plot')

Output:

Here we can see the report of three graphs and three different graphs similarly we can follow these approaches to make reports in our work using the proplot library.

Final words

In this article, we have discussed the proplot library which is a wrapper of the matplotlib library and can help us in visualizing data. Along with this, we have seen some of the methods using which we can visualize our data.  

References

PS: The story was written using a keyboard.
Picture of Yugesh Verma

Yugesh Verma

Yugesh is a graduate in automobile engineering and worked as a data analyst intern. He completed several Data Science projects. He has a strong interest in Deep Learning and writing blogs on data science and machine learning.
Related Posts

Download our Mobile App

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox
Recent Stories

Featured

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

AIM Conference Calendar

Immerse yourself in AI and business conferences tailored to your role, designed to elevate your performance and empower you to accomplish your organization’s vital objectives. Revel in intimate events that encapsulate the heart and soul of the AI Industry.

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed