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
1
vote
1 answer
Python plotnine - adding a rectangular area
I have started using plotnine and would like to create a chart with a red area above 40 and a blue area below -40.
chart with red and blue rectangles
I was able to approximate it with the following code, but it seems hacky. What is the "correct"…

martininmelbourne
- 11
- 2
1
vote
1 answer
merge color and shape in `plotnine` legend
How can one merge the color and shape in the legend of plotnine?
It seems to be possible in R. But I can't get it to work in plotnine...
Here is one example:
from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
from plotnine.data…

Hai
- 163
- 2
- 7
1
vote
2 answers
Changing color of each bar for geom_bar in plotnine
I'm making some bar charts in plotnine of counts on a single variable (based on survey responses).
I'm currently using this code:
(ggplot(df, aes ('age_cat3')) +
geom_bar(color='#F6F6F6', fill='#0C475B') +
theme_minimal() +
xlab("") +
ggtitle('Age…

Jameson
- 167
- 2
- 11
1
vote
1 answer
Hourly heatmap graph using Python’s ggplot2 implementation ‘plotnine’?
I am trying to create an hourly heatmap from within Python. A code example of this graph made in R is available here: r-graph-gallery.com/283-the-hourly-heatmap.html. It relies on ggplot2.
There also is a Python implementation of ggplot2 called…

pruefsumme
- 341
- 3
- 16
1
vote
1 answer
plotnine, keep same position of geom_bar(position='dodge') when value is missing
This minimal code
import pandas as pd
import plotnine as p9
df = pd.DataFrame({
'variable': ['a', 'b', 'b'],
'value': [1, 1, 1],
'name': ['one', 'one', 'two']
})
(
p9.ggplot(df, p9.aes(x='name', y='value', fill='variable'))
+…

lpeak
- 181
- 7
1
vote
1 answer
plotnine: How to caption?
I have a plot and I'd like to make the "source: JHU" line into a caption. There are a number of issues some open and others closed regarding this in plotnine's github.
It has been brought to my attention that if I move the axis label to the right…

hd1
- 33,938
- 5
- 80
- 91
1
vote
1 answer
Fit non-linear curve using Plotnine
Here's a working sample for producing linear curves for some user-defined metrics..
How can I have it fitted to a non-linear curve?
def plot(version, str_metric):
metric1 = [0.459, 0.5844, 0.6246, 0.6459, 0.6429, 0.6629, 0.664, 0.6722, 0.6832,…

kkgarg
- 1,246
- 1
- 12
- 28
1
vote
1 answer
Plotnine group facet_grid labels
Is there a way to group labels when using plotnine's facet_grid function?
For example, take the following DataFrame (I made the example up such that you can reproduce my problem. In real my DataFrame is much bigger but the structure is almost…

Jannik
- 965
- 2
- 12
- 21
1
vote
1 answer
for Python's plotnine, how to get % of count by total count in each facet
I am trying to get a density plot to show percentage of count by the total number in each facet.
For instance, I have this density plot:
Produced by this code:
ggplot(data, aes(x = 'ratio'))
+ geom_histogram(aes(y =…

BEN
- 63
- 6
1
vote
1 answer
Python plot data with timestamp (with hours) using plotnine
I have the following dataframe given:
point timestamp_local 0
0 A 2019-07-20 00:00:00 1
1 A 2019-07-20 01:00:00 3
2 B 2019-07-20 02:00:00 158
3 A …

Jan
- 1,180
- 3
- 23
- 60
1
vote
1 answer
How to add legend in ggplot/plotnine for multiple curves
Here is a sample code which I am using to plot two curves. How can I add the legends to the plot? I saw some post where it was suggested to add color within aes but that throws the exception
plotnine.exceptions.PlotnineError: "Could not evaluate…

kkgarg
- 1,246
- 1
- 12
- 28
1
vote
0 answers
Problems using plotnine package and exits a Keyerror::KeyError: 'reds'
I am trying to use plotnine to build graphs and I keep coming across the same KeyError problem when I want to plot. See the traceback error below.
KeyError: 'reds'
My key code is below:
p6=(ggplot(df, aes(x='SOD',y='tau',fill='age',size='age')) +
…

yuancf1024
- 67
- 1
- 5
1
vote
1 answer
How to control facet height and width in plotnine?
I have seen this post regarding ggplot2:
How to automatically adjust the width of each facet for facet_wrap?
I was wondering:
how can I achieve the same in plotnine? I haven't found anything similar to grob. I would need it for a plot that is part…

schmat_90
- 572
- 3
- 22
1
vote
1 answer
Colored lines in a ecdf
I'm trying to color some lines in a ecdf here is what I've tried:
p = (
ggplot(data, aes(color='c', x='x'))
+ stat_ecdf()
).draw()
p = (
ggplot(data)
+ geom_line(aes(color='c',x='x'), stat='ecdf')
).draw()
In both of these cases the…

Cjen1
- 1,826
- 3
- 17
- 47
1
vote
1 answer
estimated variance calculation with numpy cause an invalid value encountered error
When trying to calculate the sample mean of some data, based on the number of samples (first for 1 sample, then for 2 and so on...)
I encounter this problem:
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:3584: RuntimeWarning:…

asakasher
- 13
- 3