plotnine

Is there an equivalent to %+% for plotnine?

Is there an equivalent to %+% for plotnine? Question: In R’s ggplot2, you can modify the dataset for a saved plot with %+%. Is there an equivalent in Python’s plotnine? As an example, here is what this looks like in R: library(ggplot2) df1 <- data.frame(x = 1:10, y = 1:10 * 2) p1 <- ggplot(data …

Total answers: 1

Plot multiple dataframe in a plot with facet_wrap

Plot multiple dataframe in a plot with facet_wrap Question: I have a dataset df that looks like this: ID Week VarA VarB VarC VarD s001 w1 2 5 4 7 s001 w2 4 5 2 3 s001 w3 7 2 0 1 s002 w1 4 0 9 8 s002 w2 1 5 2 5 s002 …

Total answers: 2

Plotnine (ggplot) : Add whisker to end of geom_segment

Plotnine (ggplot) : Add whisker to end of geom_segment Question: I am doing this in python’s wonderful plotnine package, but hoping ggplotters may have a solution as well. Consider the following data and plot: df = pd.DataFrame({ ‘label’ : [‘A’,’B’,’C’,’D’], ‘start’ : [1, 1.5, 2.5, 1.75], ‘end’ : [3.85, 2.75, 4.25, 3], }) p = …

Total answers: 2

How to set the physical size of plotnine png file

How to set the physical size of plotnine png file Question: I am using python’s plotnine package to create a series of plots. Often I need the plots to fit into a space x-cms by y-cms. I can control the size of the plot via: p.save(filename=path+’fig1.png’, height=10, width=12, units = ‘cm’, dpi=300) But this sets …

Total answers: 2

QQ-Plot in Python using Plotnine

QQ-Plot in Python using Plotnine Question: 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 example data: from scipy.stats import …

Total answers: 1

Hide certain categorical element from legend in Plotnine

Hide certain categorical element from legend in Plotnine Question: In Plotnine, is it possible to hide certain legend elements? mpg_select = mpg[mpg["manufacturer"].isin(pd.Series(["audi", "ford", "honda", "hyundai"]))] I have selected only 4 manufacturers. But when I plot the data, I still see the manufacturers that are not in the data as elements for my legend. (ggplot(mpg_select, aes(x="displ", …

Total answers: 2

Is position_dodge2() working for python with plotnine?

Is position_dodge2() working for python with plotnine? Question: I’m using ggplot in python with plotnine, I have this piece of code: my_plot_availability = (ggplot(df) + aes(x=’time_elapsed’,y=’mean’,fill=’policy’) + geom_bar(position=position_dodge(),stat = “identity”, color = “black”,size = 0.5) + geom_errorbar(aes(ymin=’mean-error’, ymax=’mean+error’), width=.2,position=position_dodge(.9)) + facet_wrap(‘mobility’) + scale_fill_manual([“darkgray”, “gray”]) + labs(x = “Time elpased [s]”) + labs(y = “Mean content …

Total answers: 2

is there gridExtra/cowplot type package in Python to use with Plotnine to align subplots (i.e. marginal distributions)

is there gridExtra/cowplot type package in Python to use with Plotnine to align subplots (i.e. marginal distributions) Question: 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 …

Total answers: 2

Plotnine rotating labels

Plotnine rotating labels Question: I was wondering how one rotates the x-labels, something in the lines of: theme(axis.text.x = element_text(angle = 90, hjust = 1)) in ggplot? Thank you. Asked By: sdgaw erzswer || Source Answers: Plotnine is basically a clone of ggplot, you can call (almost) exactly that. Here’s an example : import pandas …

Total answers: 1