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
3
votes
1 answer
Drawing a surface 3D plot using "plotnine" library
Question : Using the python library 'plotnine', can we draw an interactive 3D surface plot?
Backup Explanations
What I'd like to do is, under python environment, creating an interactive 3D plot with R plot grammars like we do with ggplot2 library…

Eiffelbear
- 399
- 1
- 4
- 23
3
votes
1 answer
how to order the stacked bar using plotnine
I have the following dataframe
import pandas as pd
from plotnine import *
df = pd.DataFrame({
'variable': ['gender', 'gender', 'age', 'age', 'age', 'income', 'income', 'income', 'income'],
'category': ['Female', 'Male', '1-24', '25-54',…

quant
- 4,062
- 5
- 29
- 70
3
votes
1 answer
Changing tick labels with plotnine
I'm using plotnine to generate a scatterplot where the x-axis is pandas.Timestamp objects.
Currently, the x tick labels (e.g., "2017-07-01") are running into each other. I'd like to be able to do an arbitrary transformation of the tick labels. How…

Lorin Hochstein
- 57,372
- 31
- 105
- 141
2
votes
1 answer
plotnine side-by-side histogram with faceting
How can I get a side-by-side histogram that includes faceting? Without faceting, the histogram looks ok, but it's very difficult to compare the counts for groups Two and Three:
from plotnine import *
import pandas as pd
import numpy as np
quality…

filups21
- 1,611
- 1
- 19
- 22
2
votes
1 answer
2D density plot with plotnine (stat_density_2d)
I am trying to create a 2D density plot using python's plotnine along the lines of the last example here: https://r-graph-gallery.com/2d-density-plot-with-ggplot2.html#:~:text=A%202d%20density%20plot%20is,of%20points%20in%20this%20fragment.
It…

brb
- 1,123
- 17
- 40
2
votes
1 answer
How do I set a default line size in plotnine?
I've been using plotnine to plot in Python and I would like to set up a default line size for all plots. Unfortunately, changing line inside my custom theme only affects background elements.
In R using ggplot it is possible to run…

S -
- 349
- 3
- 19
2
votes
1 answer
How do I move the axis labels in plotnine?
I'm trying to move the x and y axis labels to be near each other at the bottom left of the chart.
This is easy enough in R's ggplot2 with:
theme(
axis.title.y = element_text(angle = 0, vjust = 0, hjust = 0.5, size = 15,
color =…

David M Vermillion
- 141
- 7
2
votes
1 answer
QQ-Plot in Python using Plotnine
I want to plot an array of values against a theoretical distribution using a QQ-Plot in Python. Ideally, I want to create the plot using the library Plotnine.
But when I try to create the plot, I'm getting error messages... here's my code with…

RamsesII
- 404
- 3
- 10
2
votes
1 answer
Display summary statistics in barplot using ggplot/plotnine
In the following simplified example, I wish to display the sum of each stacked barplot (3 for A and 7 for B), yet my code displays all the values, not the summary statistics. What am I doing wrong? Thank you in advance.
import io
import pandas as…

David
- 427
- 3
- 10
2
votes
1 answer
Plotnine theme element_blank() doesn't seem to work - perhaps I'm not importing the package correctly?
I've created a state map and would like to remove the x-axis and y-axis as these don't provided any value for this plot.
map_population_by_county = (
ggplot(map_population_by_county_data)
+ geom_map(aes(fill='Population2018'))
+ geom_label(aes(x =…

windyvation
- 497
- 3
- 13
2
votes
1 answer
reverse order of discrete x axis in plotnine
In python, I am trying to reverse the order of my x-axis so that 2015 is on the far left and 2019 is on the right. The goal is to then have 2019 on the bottom after I coord_flip() the plot. See here.
I tried using scale_x_reverse but it does not…

mfwill
- 23
- 2
2
votes
1 answer
ggplot aes: color vs group with time series data missing
I don't know if this question goes here, but as it's specific and (I think) it has one answer I'm asking it here:
I'm trying to understand certain behavior in ggplot (through plotnine from python, which is practically a copy of ggplot). In specific,…

Chris
- 2,019
- 5
- 22
- 67
2
votes
1 answer
ggplot/plotnine - adding a legend from geom_text() with specific color
I have this dataframe:
df = pd.DataFrame({'Segment': {0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'A', 5: 'B', 6: 'C', 7: 'D'},
'Average': {0: 55341, 1: 55159, 2: 55394, 3: 56960, 4: 55341, 5: 55159, 6: 55394, 7: 56960},
…

Chris
- 2,019
- 5
- 22
- 67
2
votes
2 answers
plotnine/ggplot - changing legend positions
I have this dataframe:
df = pd.DataFrame({'ymin': {0: 0.0,
1: 0.0,
2: 0.0,
3: 0.0,
4: 0.511,
5: 0.571,
6: 0.5329999999999999,
7: 0.5389999999999999},
'ymax': {0: 0.511,
1: 0.571,
2: 0.533,
3: 0.539,
4: 1.0,
5: 1.0,
6:…

Chris
- 2,019
- 5
- 22
- 67
2
votes
1 answer
python plotnine: color brewer not enough
I am using python version of ggplot with the following code and have the image attached but the colors are not enough for coloring all the categories. I am wondering what the ways are to get a palettes with more colors but still retain the relation…

lll
- 1,049
- 2
- 13
- 39