plotnine is a python plotting package that implements a "Grammar of Graphics" . It is based on the R package ggplot2 and has an API that is similar.
Questions tagged [plotnine]
179 questions
4
votes
1 answer
How do I use adjust_text with plotnine?
I am trying to adjust geom_text labels so that they don't overlap. Adjusting the labels using nudge_x, nudge_y and size does not give me a very satisfying result. I came across the adjust_text package but I don't manage to implement it to my code.…

polarpanda
- 43
- 5
4
votes
2 answers
How to graph a function in Python using plotnine library
I've been a longtime R user, recently transitioning over to Python, and I've been trying to carry over my knowledge of plotting with ggplot2, since it is so intuitive. Plotnine is supposedly the most ggplot2-esque plotting library, and I've…

Coolio2654
- 1,589
- 3
- 21
- 46
4
votes
2 answers
Plotnine bar plot order by variable
I have a question on ordering bar plots. For example:
http://pythonplot.com/#bar-counts
(ggplot(mpg) +
aes(x='manufacturer') +
geom_bar(size=20) +
coord_flip() +
ggtitle('Number of Cars by Make')
)
how to order by "mpg" ?

gcamargo
- 3,683
- 4
- 22
- 34
3
votes
3 answers
plotnine is broken with matplotlib==3.6
I am getting the following error with plotnine==0.9 and matplotlib==3.6.
File "D:\Python\Python310\lib\site-packages\plotnine\stats\stat_density_2d.py", line 3, in
import matplotlib._contour as _contour
ModuleNotFoundError: No module…

Haoran Yi
- 467
- 2
- 11
3
votes
1 answer
plotnine direct color assignment
I am not sure this is a functionality in plotnine, but I want to specifically assign colors to values.
For example if I'm creating a scatter plot
colors = {True:'#a54f7e', False:'grey'}
(ggplot(df, aes(x = "col1", y="col2", color = "col3")) +
…

mk2080
- 872
- 1
- 8
- 21
3
votes
1 answer
How to read/interpret plotnine documentation
As the saying goes, "Give a person a fish, and they won't be hungry for a day. Teach them how to fish, and they won't be hungry for a lifetime."
I cannot, for the life of me, interpret the plotnine documentation. This is not at all a criticism of…

brb
- 1,123
- 17
- 40
3
votes
1 answer
plotnine: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail
I am trying to use plotnine to generate some graphs. I import the required libraries:
from plotnine import *
from plotnine.data import mpg
And then, if I run the following code in PyCharm I get a Warning message, the window plot
shows a "No answer"…

Álvaro Méndez Civieta
- 725
- 3
- 12
- 33
3
votes
1 answer
Plotting data from different datasets using plotnine and pandas
First off, I think it would be helpful to offer some background about what I want to do. I have a time-series dataset that describes air quality in a region, with hour resolution. Each row is an observation, each column is a different parameter (eg.…

Adam Conrad
- 166
- 1
- 11
3
votes
1 answer
Add statistically significant difference between bars to plotnine plot (ggpubr equivalent)
In many plots one wants to highlight the statistical significance of an observed difference between some results. This task can be done in R using the ggpubr() or the geom.signif() extension.
An example of what I mean is here (see horizontal bars…

schmat_90
- 572
- 3
- 22
3
votes
1 answer
Plotnine's scale fill and axis position
I would like to move the x-axis to the top of my plot and manually fill the colors. However, the usual method in ggplot does not work in plotnine. When I provide the position='top' in my scale_x_continuous() I receive the warning: PlotnineWarning:…

Jack Armstrong
- 1,182
- 4
- 26
- 59
3
votes
1 answer
python plotnine: how to change color scale
i have the following plot with the code below, but I keep in the color legend, it does not separate well that I cannot tell the differences very well from the plots. I am wondering how I can change the color bar from, for example, very light green,…

lll
- 1,049
- 2
- 13
- 39
3
votes
1 answer
Changing legend in plotnine
I have a question regarding legend in a plotnine plot.
import pandas as pd
import numpy as np
from pandas.api.types import CategoricalDtype
from plotnine import *
from plotnine.data import mpg
%matplotlib inline
c=…

B.Germ
- 85
- 1
- 3
- 8
3
votes
1 answer
Add text to figure using python's plotnine
I would like to add a label to a line in plotnine. I get the following error when using geom_text:
'NoneType' object has no attribute 'copy'
Sample code below:
df = pd.DataFrame({
'date':pd.date_range(start='1/1/1996', periods=4*25,…

brb
- 1,123
- 17
- 40
3
votes
2 answers
is there gridExtra/cowplot type package in Python to use with Plotnine to align subplots (i.e. marginal distributions)
This is related to the following posts on aligning subplots in ggplot2 in R:
Scatterplot with marginal histograms in ggplot2
How to plot Scatters with marginal density plots use Python?
Perfectly align several plots
There are many more links on…

codingknob
- 11,108
- 25
- 89
- 126
3
votes
1 answer
How to scale x-axis with intervals of 1 hour with x data type being timedelta64[ns]
My x-axis being time in hours and minutes, I am not able to plot in intervals of 1 hour, by default it is plotting in interval of 5 hours.
Here x-axis is "newtime" which is in the format below
00:00:00
00:15:00
00:30:00
00:45:00
01:00:00
…

Srihari Uttanur
- 35
- 11