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
- What is Proplot?
- Plots using Proplot.
- Creating figure
- Creating subplots
- 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.
Subscribe to our Newsletter
Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
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.
Let’s start by making a single figure.
import proplot as pplt fig = pplt.figure() ax = fig.subplot() ax.plot()
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: 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)
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.
Let’s see how we can make the subplots in the figure.
import proplot as pplt
fig, axs = pplt.subplots(ncols=2, nrows = 1)
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'
Here we can see that we have filled the data in graphs.
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)
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 ax.bar(data, width=2, negpos=True, edgecolor='B') ax.format(title='Bar plot') # Area plot ax = axs ax.area(data, negpos=True, edgecolor='B') ax.format(title='Area plot') # Line plot ax = axs ax.vlines(data, linewidth=1, negpos=True) ax.format(title='Line plot')
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.
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.