Updated On : Sep-27,2021 Tags plotnine, quick-plots
Plotnine: Quick Plots with One Function Call [Python]

Plotnine: Quick Plots with One Function Call

Plotnine is a python data visualization library based on the concept of the grammar of the graphics. The grammar of the graphics concept divides visualization into layers and lets us provide information for each layer. At last, we add up all layers to create the final visualization. It gives us the flexibility of declaring details about visualization parts separately like giving axis labels separately, giving figure size details separately, giving mapping details about X/Y axis separately, giving data details separately, etc. R Programming has a library named ggplot2 which also implements the concept of the grammar of graphics for creating visualizations. Plotnine has API almost the same as that of ggplot2. The code created in python using plotnine will most probably work with ggplot2 as well with minor changes if needed. As a part of this tutorial, we are going to introduce one function of plotnine and how to use it to create simple charts with just one line of code. We have already covered a tutorial on plotnine where we explore the API of it with simple examples and explain the concept of the grammar of graphics. We recommend that readers check that tutorial as well if they want to know about it.

We'll be using function qplot() from plotnine to create charts quickly as a part of this tutorial. It takes care of all internal layers of creating a visualization.


Definition of qplot()

  • qplot(x=None,y=None,data=None,facets=None,geom='auto',xlim=None,ylim=None,main=None,xlab=None,ylab=None,asp=None,**kwargs) - This method takes as input X axis column name, Y axis column name and data to create visualization from it. It accepts few more parameters to create different visualizations which we have explained below.
    • The parameter x accepts string (dataframe column name) or array for X-axis of the chart.
    • The parameter y accepts string (dataframe column name) or array for Y-axis of the chart.
    • The parameter data accepts the dataframe as input.
    • The parameter geom accepts string or list of strings as input specifying geometric objects that will be plotted in the chart. The geometric objects are points, bars, histogram, cols, etc. The default value if 'auto' which plots scatter chart if x and y are provided else plots histogram if only 'x' is provided. The value provided here will be used internally to call method geom_*() corresponding to it. If we provide a list of strings then it'll create all geometric objects on the chart.
    • The facets parameter accepts a string column name from data based on which subplots will be created. This is a categorical column of data based on whose different values, we want to see the relationship between other data columns.
    • The xlim and ylim parameters accepts tuple of length two specifying limits for X and Y-axis.
    • The main parameter accepts string specifying the title of the chart.
    • The xlab and ylab parameters accepts string specifying labels for the X and Y-axis.
    • The asp parameter accepts float specifying aspect ratio of height and width of visualization.
    • All extra parameters provided to this method call will be passed to geom_*() method based on geom parameter.

We'll now start with our tutorial by importing all necessary modules. We'll be using datasets available from data module of plotnine for the creation of various visualizations.

In [1]:
import plotnine

from plotnine import qplot

from plotnine.data import mpg, presidential, economics

Load Datasets

We'll be using 2 different datasets as a part of our tutorial. All of them are available as pandas dataframe from plotnine.data module.

  • mpg - This dataset has information about different car models manufactured by different manufacturers. It has information like model's manufacturer, model name, engine displacement, launch year, cylinders, city MPG, highway mpg, class, etc.
  • economics - This dataset has time-series information about the united states from 1967 to 2015 on a monthly basis. It has attributes like population, personal savings rate, unemployment rate, etc.
In [2]:
mpg.head()
Out[2]:
manufacturer model displ year cyl trans drv cty hwy fl class
0 audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
1 audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
2 audi a4 2.0 2008 4 manual(m6) f 20 31 p compact
3 audi a4 2.0 2008 4 auto(av) f 21 30 p compact
4 audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
In [3]:
economics.head()
Out[3]:
date pce pop psavert uempmed unemploy
0 1967-07-01 507.4 198712 12.5 4.5 2944
1 1967-08-01 510.5 198911 12.5 4.7 2945
2 1967-09-01 516.3 199113 11.7 4.6 2958
3 1967-10-01 512.9 199311 12.5 4.9 3143
4 1967-11-01 518.1 199498 12.5 4.7 3066
In [4]:
economics.tail()
Out[4]:
date pce pop psavert uempmed unemploy
569 2014-12-01 12122.0 320201 5.0 12.6 8688
570 2015-01-01 12080.8 320367 5.5 13.4 8979
571 2015-02-01 12095.9 320534 5.7 13.1 8705
572 2015-03-01 12161.5 320707 5.2 12.2 8575
573 2015-04-01 12158.9 320887 5.6 11.7 8549

Scatter Plots

As a part of this section, we'll explain how to create scatter plots using qplot().

Below we have created our first scatter plot with simply one line of code. We have given mpg dataset as input and instructed to use hwy column's data for X-axis and cty columns data as Y-axis. The qplot() method then creates a scatter chart from details.

In [ ]:
qplot(data=mpg, x="hwy", y="cty")

Plotnine: Quick Plots with One Function Call

Below we have created another scatter plot that has the same X and Y-axis as our previous chart but we have asked to color points of a chart based on the number of cylinders in the model of the car. We have set color parameter to value cyl for color encoding. We have also provided labels for X/Y axes and a title for the chart using xlab,ylab, and main parameters. We have set the aspect ratio of the chart to 0.6 to make it a rectangle where width is more than height. The extra color parameter that we provided will be passed to geom_point() method internally.

In [ ]:
qplot(data=mpg, x="hwy", y="cty",
      color="cyl",
      xlab="Highway MPG", ylab="City MPG",
      main="Highway MPG vs City MPG color-encoded by Cylinders",
      asp=0.6
     )

Plotnine: Quick Plots with One Function Call

Below we have created another scatter plot that has the same X and Y axis as previous charts but this time we have used an engine displacement column to decide the size of points in the chart. We have done that by providing string 'displ' to size parameter of the chart. The extra parameter size that we provided in the method call will be passed to geom_point() method internally.

In [ ]:
qplot(data=mpg,
      x="hwy", y="cty",
      size="displ",
      xlab="Highway MPG", ylab="City MPG",
      main="Highway MPG vs City MPG size-encoded by Engine Displacement")

Plotnine: Quick Plots with One Function Call

Below we have created another scatter chart with the same X and Y-axis as our previous charts. But this time we have color encoded and shape encoded points of a chart based on a number of cylinders. We have done that by providing parameters color and shape with value cyl. The string cyl is surrounded with factor() to inform that its value should be used as categorical values. Parameters color and shape that we provided will be passed to geom_point() method internally for encoding purposes.

In [ ]:
qplot(data=mpg,
      x="hwy", y="cty",
      color="factor(cyl)", shape="factor(cyl)",
      xlab="Highway MPG", ylab="City MPG",
      main="Highway MPG vs City MPG Encoded by Cylinders")

Plotnine: Quick Plots with One Function Call

Bar Charts

As a part of this section, we'll explain how to create bar charts using qplot() method. There are two different ways to create a bar chart based on the value of parameter geom.

  • 'bar' - It'll call geom_bar() method internally which will create bar chart based on counts only. It only lets us provide X value and the height of bars will be decided based on counts of X-axis values. It does not let us specify the height of bars separately.
  • 'col' - It'll call geom_col() method internally which will create bar chart. It let us provide both X and Y axis values. The value provided as Y-axis will be used to decide the height of the bar chart.

Below we have created our first bar chart showing model counts per class. We have provided mpg data, class string to x parameter and bar string to geom parameter for creating this chart. The bar geom internally calls geom_bar() function to create bar chart of counts.

In [ ]:
qplot(data=mpg,
      x="class",
      geom="bar",
      xlab="Car Class", ylab="Model Counts",
      main="Model Counts Per Car Class"
     )

Plotnine: Quick Plots with One Function Call

Below we have created another bar chart using bar geom which uses the same combinations as our previous chart with only one difference. We have provided fill parameter with a number of cylinders. This way it'll color each bar based on the distribution of cylinders for each class.

We can also provide position parameter with value 'dodge' if we want side by side bar chart instead of a stacked bar chart.

In [ ]:
qplot(data=mpg,
      x="class", fill="factor(cyl)",
      width=0.7,
      geom="bar",
      xlab="Car Class", ylab="Model Counts",
      main="Model Counts Per Car Class color-encoded by Cylinders"
     )

Plotnine: Quick Plots with One Function Call

We'll now explain how to create bar charts where we can provide height for bars. We'll be using 'col' string for geom parameter for creating bar charts.

We have first created an intermediate data frame where we have an average value of mpg dataframe columns based on car class. We have created this dataframe by grouping the original mpg dataframe based on class column and then taken the mean of entries to get the average of each column per car class.

In [11]:
mpg_by_class = mpg.groupby(by="class").mean().reset_index()

mpg_by_class
Out[11]:
class displ year cyl cty hwy
0 2seater 6.160000 2004.400000 8.000000 15.400000 24.800000
1 compact 2.325532 2003.212766 4.595745 20.127660 28.297872
2 midsize 2.921951 2003.609756 5.317073 18.756098 27.292683
3 minivan 3.390909 2003.090909 5.818182 15.818182 22.363636
4 pickup 4.418182 2003.636364 7.030303 13.000000 16.878788
5 subcompact 2.660000 2003.114286 5.028571 20.371429 28.142857
6 suv 4.456452 2003.790323 6.967742 13.500000 18.129032

We have now created a bar chart using the dataframe created in the previous cell. We have provided values for x and y parameters. The height of the bar will be decided based on values from the column provided through parameter y.

In [ ]:
qplot(data=mpg_by_class,
      x="class", y="hwy",
      xlab="Car Class", ylab="Avg. Highway MPG",
      geom="col",
      main="Average Highway MPG Per Car Class")

Plotnine: Quick Plots with One Function Call

We'll now explain one more example of creating a bar chart where we'll be creating a side-by-side bar chart. We'll be modifying our original mpg dataframe to create an intermediate dataframe that we'll use for our purpose.

Below we have created a dataframe that has an average for each column of dataframe for each combination of class and cyl. We have created this dataframe by first grouping the original mpg dataframe based on class and cyl columns and then taking an average of entries that falls in each combination of both to get the average for each combination.

In [13]:
mpg_by_class_cyl = mpg.groupby(by=["class","cyl"]).mean().dropna().reset_index()

mpg_by_class_cyl
Out[13]:
class cyl displ year cty hwy
0 2seater 8 6.160000 2004.400000 15.400000 24.800000
1 compact 4 2.065625 2003.500000 21.375000 29.468750
2 compact 5 2.500000 2008.000000 21.000000 29.000000
3 compact 6 2.938462 2001.769231 16.923077 25.307692
4 midsize 4 2.262500 2004.062500 20.500000 29.187500
5 midsize 6 3.221739 2002.913043 17.782609 26.260870
6 midsize 8 4.750000 2008.000000 16.000000 24.000000
7 minivan 4 2.400000 1999.000000 18.000000 24.000000
8 minivan 6 3.490000 2003.500000 15.600000 22.200000
9 pickup 4 2.700000 2002.000000 16.000000 20.666667
10 pickup 6 3.840000 2002.600000 14.500000 17.900000
11 pickup 8 4.965000 2004.400000 11.800000 15.800000
12 subcompact 4 1.933333 2001.571429 22.857143 30.809524
13 subcompact 5 2.500000 2008.000000 20.000000 28.500000
14 subcompact 6 3.385714 2005.428571 17.000000 24.714286
15 subcompact 8 4.760000 2004.400000 14.800000 21.600000
16 suv 4 2.550000 2003.500000 18.000000 23.750000
17 suv 6 3.750000 2002.375000 14.500000 18.500000
18 suv 8 5.155263 2004.447368 12.131579 16.789474

Below we have created a bar chart where the x-axis represents a class of car models and the y-axis represents the average highway MPG for the car models. We have instructed the method to use different colors based on the number of cylinders. This will show the average highway MPG for each combination of car class and cylinders. The main difference in this chart is position parameter which is set to string 'dodge'. This will instruct plotnine to create side by the side bar chart. If we don't provide this parameter then it'll stack bars on one another for each car class and we'll have one bar per class colored by cylinders.

If we need to create side by side bar chart then we need to set position parameter with value 'dodge'.

In [ ]:
qplot(data=mpg_by_class_cyl,
      x="class", y="hwy", fill="factor(cyl)", position="dodge",
      xlab="Car Class", ylab="Avg. Highway MPG",
      geom="col", width=0.8,
      main="Average Highway MPG Per Car Class")

Plotnine: Quick Plots with One Function Call

Line Charts

As a part of this section, we'll explain how to create line charts using qplot() function.

Below we have created the first line chart using economics dataset. We have used date column as X-axis and pop column as the Y axis of a line chart. We have provided 'line' string to geom parameter to instruct plotnine for creating line chart. It'll call geom_line() method to create line chart internally.

In [ ]:
qplot(data=economics,
      x="date", y="pop", #color="'tomato'",
      geom="line",
      xlab="Date", ylab="Population(thousands)", margins=True,
      main="US Population Line Chart")

Plotnine: Quick Plots with One Function Call

We generally need to include more than one line in our line chart. We can do that as well. We'll be modifying our original dataframe and create one intermediate dataframe in order to create a line chart with 2 lines. The first line will show the personal savings rate over time and the second line will show the unemployment rate.

Below we have created an intermediate dataframe where we have the first column with an entry for the date, the second column represents the name of the columns from the original dataframe and the third column represents the value of the column provided in the second column for that date. We have created this dataframe using melt() function of pandas. The second column will have values psavert and uempmed for each date.

In [16]:
import pandas as pd

economics2 = pd.melt(economics, id_vars=["date"], value_vars=["psavert", "uempmed"], var_name="Attributes", value_name="Attr_Value")

economics2.head()
Out[16]:
date Attributes Attr_Value
0 1967-07-01 psavert 12.5
1 1967-08-01 psavert 12.5
2 1967-09-01 psavert 11.7
3 1967-10-01 psavert 12.5
4 1967-11-01 psavert 12.5

We have now created a line chart with 2 lines using the dataframe created in the previous cell. The first line represents the personal savings rate and the second line represents the unemployment rate.

In [ ]:
qplot(data=economics2,
      x="date", y="Attr_Value",  color="Attributes",
      geom="line",
      xlab="Date", ylab="",
      main="Personal Savings Rate/Unemployment Duration Line Chart")

Plotnine: Quick Plots with One Function Call

Area Charts

As a part of this section, we'll explain how to create area charts using qplot() function.

Below we have created an area chart using the same parameter settings as our first line chart. The only difference is that we have provided string 'area' to geom parameter to instruct plotnine to create an area chart. The x-axis represents a date and the y-axis represents the unemployment rate. The area below the line is filled. This method internally calls geom_area() method to create an area chart.

In [ ]:
qplot(data=economics,
      x="date", y="uempmed", #fill="'tomato'",
      geom="area",
      xlab="Date", ylab="Unemployment Duration",
      main="Median Unemployment Duration Area Chart")

Plotnine: Quick Plots with One Function Call

Below we have created another area chart using an intermediate economics dataframe created when explaining line charts. The parameter settings are exactly the same as that of the line chart with only one difference which is using 'area' string for geom parameter for the area chart.

In [ ]:
qplot(data=economics2,
      x="date", y="Attr_Value", fill="Attributes",
      geom="area",
      xlab="Date", ylab="",
      main="Personal Savings and Unemployment Duration Area Chart")

Plotnine: Quick Plots with One Function Call

Histogram

In this section, we'll explain how to create histograms using qplot() function.

Below we have created a histogram showing the distribution of highway MPG. We have provided geom parameter with value 'histogram' for instructing plotnine to create histogram based on data. Histogram only needs us to provide x parameter value. We can also provide a number of bins using bins parameter. It'll pass bins parameter to geom_histogram() method internally.

In [ ]:
qplot(data=mpg,
      x="hwy", bins=20,
      geom="histogram",
      xlab="Highway MPG", ylab="Freq",
      main="Highway MPG Histogram")

Plotnine: Quick Plots with One Function Call

Box Plot

In this section, we'll explain how to create a boxplot using qplot() function.

Below we have created the first boxplot showing the distribution of highway MPG for each cylinder’s count. We have set x parameter with value cyl and y parameter with value hwy for creating this chart. The geom parameter is set with string value 'boxplot'. This will instruct plotnine internally to call geom_boxplot() method to create boxplot.

In [ ]:
qplot(data=mpg,
      x="factor(cyl)", y="hwy",
      geom="boxplot",
      xlab="Cylinders", ylab="Highway MPG",
      main="Highway MPG Distribution box plot per Cylinder")

Plotnine: Quick Plots with One Function Call

Below we have created another box plot showing the distribution of city MPG for each manufacturer.

In [ ]:
qplot(data=mpg,
      x="manufacturer", y="cty", color="'tomato'",
      geom="boxplot",
      xlab="Cylinders", ylab="City MPG",
      main="City MPG Distribution Box Plot per Manufacturer")

Plotnine: Quick Plots with One Function Call

Heatmap

In this section, we'll explain steps to create a heatmap using qplot() function.

The first heatmap that we'll create will show a correlation between columns of mpg dataset.

We have first created a dataset that has correlation data for mpg dataset using corr() method of pandas dataframe. We have then modified the structure of the correlation dataframe so that the new dataframe has only 3 columns. The first column and second column represent a combination of mpg column names and the third column represents the correlation between that combination. We'll be using this modified dataframe for creating a heatmap.

In [23]:
mpg_corr = mpg.corr()

data = []
for val1 in mpg_corr.index:
    for val2 in mpg_corr.columns:
        data.append([val1, val2, mpg_corr.loc[val1, val2]])

mpg_corr = pd.DataFrame(data=data, columns=["Val1", "Val2", "Correlation"])

mpg_corr
Out[23]:
Val1 Val2 Correlation
0 displ displ 1.000000
1 displ year 0.147843
2 displ cyl 0.930227
3 displ cty -0.798524
4 displ hwy -0.766020
5 year displ 0.147843
6 year year 1.000000
7 year cyl 0.122245
8 year cty -0.037232
9 year hwy 0.002158
10 cyl displ 0.930227
11 cyl year 0.122245
12 cyl cyl 1.000000
13 cyl cty -0.805771
14 cyl hwy -0.761912
15 cty displ -0.798524
16 cty year -0.037232
17 cty cyl -0.805771
18 cty cty 1.000000
19 cty hwy 0.955916
20 hwy displ -0.766020
21 hwy year 0.002158
22 hwy cyl -0.761912
23 hwy cty 0.955916
24 hwy hwy 1.000000

Below we have created our first heatmap using qplot() function. We have provided the first column of the dataframe to x parameter, the second column name to y parameter, and the third correlation column name to label parameter. The fill parameter will inform the color of the rectangles based on correlation values. The label parameter will inform to use the value of correlation as a label. The value of geom parameter is set with a list of strings. The first string is 'tile' which will be responsible for creating rectangles for each combination with colors in them and the second string is 'text' which will show actual correlation values inside of each rectangle. We have also provided format_string parameter with string format that we want to use for labels inside of rectangles.

Please make a NOTE that this is the first time we have set geom parameter with more than one string. This example demonstrates how we can combine more than one geometric object.

In [ ]:
qplot(data=mpg_corr,
      x="Val1", y="Val2", fill="Correlation", label="Correlation",
      format_string='{:.2f}',
      geom=["tile", "text"],
      xlab="", ylab="",
      main="MPG Dataset Columns Correlation Heatmap",
     )

Plotnine: Quick Plots with One Function Call

We'll now create one more heatmap where we'll show the average highway MPG for each manufacturer and car class combination.

To do that, we have created an intermediate dataframe that has an entry for average values of dataframe columns for each combination of manufacturer and car class. We have created this dataframe by using the grouping functionality of pandas. We'll use this dataframe to create our second heatmap.

In [25]:
mpg2 = mpg.groupby(["manufacturer", "class"]).mean().fillna(0).reset_index()

mpg2
Out[25]:
manufacturer class displ year cyl cty hwy
0 audi 2seater 0.000000 0.000000 0.000000 0.000000 0.000000
1 audi compact 2.380000 2003.200000 4.933333 17.933333 26.933333
2 audi midsize 3.366667 2005.000000 6.666667 16.000000 24.000000
3 audi minivan 0.000000 0.000000 0.000000 0.000000 0.000000
4 audi pickup 0.000000 0.000000 0.000000 0.000000 0.000000
... ... ... ... ... ... ... ...
100 volkswagen midsize 2.400000 2002.857143 4.857143 18.571429 27.571429
101 volkswagen minivan 0.000000 0.000000 0.000000 0.000000 0.000000
102 volkswagen pickup 0.000000 0.000000 0.000000 0.000000 0.000000
103 volkswagen subcompact 2.133333 2002.000000 4.333333 24.000000 32.833333
104 volkswagen suv 0.000000 0.000000 0.000000 0.000000 0.000000

105 rows × 7 columns

Below we have created our second heatmap using the intermediate dataframe which we created in the previous cell. We have provided class column as x parameter, manufacturer column as y parameter and hwy column as fill & label parameters. We have also modified format_string to include text mpg in it.

In [ ]:
heatmap2 = qplot(data=mpg2,
                  x="class", y="manufacturer", fill="hwy", label="hwy",
                  format_string='{:.2f} mpg', size=10,
                  geom=["tile", "text"],
                  xlab="Class", ylab="Manufacturer",
                  main="Average Highway MPG per Manufacturer per Class",
                 )

heatmap2

Plotnine: Quick Plots with One Function Call

Below we have explained how we can change the default colormap of the heatmap. We can call scale_fill_cmap() method with the appropriate colormap name and then add it to the chart to change the default colormap.

In [ ]:
from plotnine import scale_fill_cmap

heatmap2 + scale_fill_cmap(cmap_name="Blues")

Plotnine: Quick Plots with One Function Call

Subplots

As a part of this section, we'll explain how we can use facets parameter of qplot() method to create subplots based on a categorical column of data. We have imported theme function from plotnine which we'll use to modify the default figure size. As we had explained earlier, the facets parameter accepts the categorical column name of the dataset. The dataset will be divided based on individual values of a categorical column and one chart will be created for each categorical value using other parameters settings of qplot() method.

In [28]:
from plotnine import theme

Below we have created our first faceted chart using mpg dataset showing the relationship between highway MPG and city MPG for each value of cyl column.

In [ ]:
qplot(data=mpg, x="hwy", y="cty", #color="displ",
      facets="cyl",
      xlabe="Highway MPG", ylab="City MPG",
      main="Highway MPG vs City MPG")\
+ \
theme(figure_size=(11,6))

Plotnine: Quick Plots with One Function Call

Below we have created one more faceted plot which has almost the same code as the previous cell with only one addition. We have color-encoded points of charts based on engine displacement.

In [ ]:
qplot(data=mpg, x="hwy", y="cty", color="displ",
      facets="cyl",
      xlabe="Highway MPG", ylab="City MPG",
      main="Highway MPG vs City MPG")\
+ \
theme(figure_size=(11,6))

Plotnine: Quick Plots with One Function Call

Below we have created another faceted chart where each individual chart is a bar chart representing model counts per cylinders for each car class.

In [ ]:
qplot(data=mpg,
      x="cyl",
      geom="bar", facets="class",
      xlab="Cylinders", ylab="Model Counts",
      main="Model Counts Per Cylinders for each Car Class"
     )\
+ \
theme(figure_size=(11,7))

Plotnine: Quick Plots with One Function Call

We'll now explain another example of creating a faceted chart of bar charts. We have first created an intermediate dataframe for our purpose which has average values of dataframe columns for each combination of manufacturer and cylinders. We'll be using this column to create our faceted chart.

In [32]:
mpg_avg = mpg.groupby(["manufacturer", "cyl"]).mean().fillna(0).reset_index()

mpg_avg.head()
Out[32]:
manufacturer cyl displ year cty hwy
0 audi 4 1.900000 2003.5 19.125000 28.125000
1 audi 5 0.000000 0.0 0.000000 0.000000
2 audi 6 2.933333 2003.0 16.444444 25.333333
3 audi 8 4.200000 2008.0 16.000000 23.000000
4 chevrolet 4 2.400000 2003.5 20.500000 28.500000

Below we have created a faceted chart where each individual bar chart represents the average city MPG for car cylinders per manufacturer.

In [ ]:
qplot(data=mpg_avg,
      x="cyl", y="cty",
      geom="col", facets="manufacturer",
      xlab="Cylinders", ylab="Avg City MPG",
      main="Avg City MPG Per Cylinders for each Manufacturer"
     )\
+ \
theme(figure_size=(11,7))

Plotnine: Quick Plots with One Function Call

Below we have created a faceted chart where an individual chart is a line chart. The first line chart represents personal savings over time and the second chart represents the unemployment rate over time. We have used one intermediate dataframe that we had created during our line charts section.

In [ ]:
qplot(data=economics2,
      x="date", y="Attr_Value",  facets="Attributes", color="Attributes",
      geom="line", asp=0.8, margins=True,
      xlab="Date", ylab="",
      main="Personal Savings Rate/Unemployment Duration Line Chart",)\
+ \
theme(figure_size=(11,6))

Plotnine: Quick Plots with One Function Call

This ends our small tutorial explaining how we can use qplot() method to quickly create a chart with just one function call and one line of code. Please feel free to let us know your views in the comments section.

References



Sunny Solanki  Sunny Solanki