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
problem faceting plot with plotnine 0.6.0 in python
I'm trying to create a simple plot with lines colored according to a factor variable using plotnine 0.6.0 in python 3.7.4.
import pandas as pd
import plotnine as pn
import datetime
# data
df = pd.DataFrame(
{'name': ('Eric', 'Eric', 'Eric',…

filups21
- 1,611
- 1
- 19
- 22
1
vote
1 answer
plotnine/ggplot (Python) - stacked bars + width manipulation
I have this dataframe:
df = pd.DataFrame({'Segment': {0: 'A', 1: 'B', 2: 'C', 3: 'D'},
'%Value_S=0': {0: 0.489, 1: 0.429, 2: 0.467, 3: 0.461},
'%Value_S=1': {0: 0.511, 1: 0.571, 2: 0.533, 3: 0.539},
'%Total': {0: 0.148, 1: 0.076, 2: 0.3, 3:…

Chris
- 2,019
- 5
- 22
- 67
1
vote
1 answer
python plotnine: labeller in facet_grid not changing the facet title
I want to change the facet title in plotnine (python ggplot) when 2 variables are used in faceting WITHOUT changing the data itself.
Example: using mpg data
pretty = p9.ggplot(data=mpg, mapping = p9.aes(x='hwy', y='displ'))+ p9.geom_point(alpha =…

lll
- 1,049
- 2
- 13
- 39
1
vote
1 answer
ggplot2 / plotnine: How to plot grouped chart for a melted df?
I subset and melt an Airbnb dataset and try to plot a grouped chart:
from plotnine import *
airbnb_melted = pd.melt(airbnb_newcomers, id_vars =['host_id'], value_vars =['host_identity_verified', 'host_is_superhost'])
print(airbnb_melted)
The…

vcai01
- 53
- 1
- 1
- 8
1
vote
1 answer
fixing bar size with ggplot in facet_grid()
I'm trying to make the bars of the plot of the same size with this code:
my_plot_replicas = (ggplot(df)
+ aes(x='algorithm',y='replicas',fill='algorithm')
+ geom_col(position=position_dodge2(preserve='single'))
+…

BlueMountain
- 197
- 2
- 17
1
vote
1 answer
How to add geom_hlines legend into plot in plotnine?
I would like to add a legend to my plot that consist of all hline's statistics description. Is there any way to do it?
Link to plot
def test_plot():
Q1=test['age'].quantile(0.25)
Q3=test['age'].quantile(0.75)
IQR=Q3-Q1
fig = (
ggplot(test) +
…

Tr4nce
- 21
- 4
1
vote
1 answer
Errorbars in Plotnine
I have the following Python plotnine code:
ggplot(df)
+ geom_point(aes("Distance", "Force"), size=2)
+ geom_path(aes("xfit", "yfit"))
Where Distance, Force, xfit, and yfit are just lists of values from my dataframe.
That produces this…

Anson Biggs
- 312
- 3
- 13
1
vote
1 answer
How do change the legend on the right of the ggplot from continuous to discrete?
I am using plotnine to make a plot with multiple lines in it. The pandas dataframe looks like this:
df
TIMESTAMP TEMP RANK TIME
0 2011-06-01 00:00:00 24.3 1.0 0.000000
1 2011-06-01 00:05:00 24.5 1.0 …

Akshay Gaur
- 2,235
- 21
- 26
1
vote
1 answer
Timeline in Python
Is there any way to create a timeline in Python similar to this post using only 1 vizualiation package and no other setup? I have tried to use the plotnine package to use ggplot2 within Python but this is quite cumbersome to get it to work.…

Michael
- 1,281
- 1
- 17
- 32
1
vote
0 answers
Plotting pandas dataframe after doing pandas melt is slow and creates strange y-axis
This could be caused by me not understanding how pandas.melt works but I get strange behaviour when plotting "melted" dataframes using plotnine. Both frames has been converted from wide to long format. One frame with a column containing string…

Solid7
- 54
- 6
1
vote
0 answers
How to do multiple density plots in plotnine
I'm having trouble finding useful documentation or examples of doing multiple density plots in plotnine.
I've tried several approaches but still get an error.
p = (ggplot(data=gg,aes(x='u',color='x')) + geom_density()
print(p)
TypeError:…

bill fite
- 43
- 5
1
vote
1 answer
Omit axes with facet_grid - plotnine
import pandas as pd
from plotnine import *
df=pd.DataFrame({'A':[1,1,1,1],'B':[1,9,5,11],'C':['x','x','y','y'],'D':['a','b','a','b']})
p=ggplot(df,aes('A','B'))
p + geom_bar(stat="identity") + facet_grid('D~C',scales='free_y')
This will draw axes…

HappyPy
- 9,839
- 13
- 46
- 68
1
vote
2 answers
Plotnine custom bar polt colors
I am trying to plot two overlay bar plots over 4 different categories. My dataset looks something like:
category count_first count_second
a 15 80
b 18 50
c 12 99
d 11 …

sdgaw erzswer
- 2,182
- 2
- 26
- 45
1
vote
1 answer
Creating a custom legend in plotnine
I'm having trouble in plotnine customising the legend beyond what's possible through aes()
I have the following code:
import pandas as pd
from plotnine import *
data1 = {'dilution': [2.000000, 2.477121, 2.954243, 3.431364, 3.908485, 4.385606,…

Simon
- 13
- 1
- 4
1
vote
1 answer
PyCharm not plotting graphs?
I've been trying to figure out plotting with plotnine, being the most ggplot2-esque library in Python from what I've heard, and I'm having difficulty accomplishing it in PyCharm in Python scripts. This seems like a problem that has many solutions…

Coolio2654
- 1,589
- 3
- 21
- 46