Questions tagged [plotnine]

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.

179 questions
1
vote
2 answers

How to set the physical size of plotnine png file

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…
brb
  • 1,123
  • 17
  • 40
1
vote
1 answer

Python Plotnine (ggplot) add mean line per color to plot?

Using plotnine in python, I'd like to add dashed horizontal lines to my plot (a scatterplot, but preferably an answer compatible with other plot types) representing the mean for every color separately. I'd like to do so without manually computing…
Mathijs
  • 19
  • 3
1
vote
1 answer

How to create horizontal histogram in Python's plotnine?

I'm using plotnine recently and wanted to plot a horizontal histogram (i.e., a histogram with horizontal bars). The following example illustrates the vertical histogram: from plotnine import * import numpy as np df = pd.DataFrame({'values':…
catastrophic-failure
  • 3,759
  • 1
  • 24
  • 43
1
vote
1 answer

How to extract y-values from my regression line in plotnine (ggplot)

#So my code looks like this but I have no idea how to extract y-values from the regression line or #maybe even show the equation of the curve. import plotnine as p9 from scipy import stats #calculate best fit line slope, intercept, r_value, p_value,…
Heidi
  • 11
  • 2
1
vote
1 answer

plotnine shows discrete values in the wrong place

I am trying to make a figure that shows time on the x-axis and dots on the y-axis whenever a column has a specific (discrete) value. Here is some example data: dat = pd.DataFrame({ 'time': [0, 15, 30], 'A': [np.nan, np.nan, 'A'], 'B':…
1
vote
1 answer

How to reorder or sort categories based on another variable values in python plotnine?

I am trying to use plotnine in python and couldn't do fct_reorder of r in python. Basically I would like to plot categories from the categorical variable to arrange on x axis based on the increasing value from another variable but I am unable to do…
ViSa
  • 1,563
  • 8
  • 30
1
vote
1 answer

Plotnine : How to remove legend boxes around lines in geom_line()

Consider the following plotnine plot. How do I remove the pseudo boxes around the lines in the the legend (circled in the screenshot). These pseudo boxes don't appear in ggplot. I have looked at all the options in theme, but none do the…
brb
  • 1,123
  • 17
  • 40
1
vote
1 answer

Plotnine (ggplot) : Annotation outside of plotting area

I have the following plot in plotnine. I would like to add a label showing the mean value for the series to the left of the y-axis (essentially in line with the y-axis labels). Even better would be if the label could be shaped as follows, pointing…
brb
  • 1,123
  • 17
  • 40
1
vote
1 answer

How do I reorder plot by multiple variables?

I am trying to reorder plot first by am and then by mpg. Attached in the result in R using ggplot2. I trying to attain the same result using siuba and plotnine. Below is my code so far. ( mtcars >> arrange(_.am, _.mpg) >> mutate(model =…
1
vote
1 answer

Fix the distance between the plotting area and x-axis label in plotnine / ggplot

I want to fix/set (not increase) the distance between the plotting area and the x-axis label in plotnine/ggplot. library(ggplot2) ggplot(diamonds) ggplot(diamonds) + geom_point(aes(x=carat, y=price, color=cut)) + geom_smooth(aes(x=carat, y=price,…
Esme_
  • 1,360
  • 3
  • 18
  • 30
1
vote
0 answers

replicate a ggplot plot functionality in seaborn

I am doing a linear regression on a few timeseries (different colors) and plotting the equation on the same graph. In R using ggplot and ggpubr this is very easy. here is the example and the output: library(tidyverse) library(ggpubr) economics_long…
Courvoisier
  • 904
  • 12
  • 26
1
vote
1 answer

Display a bar chart with proportions and fill not working

I'm using plotnine to draw some plots. When I try to display a bar chart of proportion rather than count, the fill argument becomes useless. I noticed that removing the group=1 arguments helps to get the fill argument "active" again. However,…
Jannik
  • 965
  • 2
  • 12
  • 21
1
vote
1 answer

Free y axis in ggplot and plotnine

I need help with a plot in python. I used the example dataset mpg. import pandas as pd import numpy as np from plotnine import * from plotnine.data import * import matplotlib.pyplot as plt %matplotlib inline mpg.head() mpg =…
JocHwo
  • 109
  • 2
  • 9
1
vote
1 answer

How to place geom_text labels outside the plot boundary in plotnine

Using plotnine I am trying to plot line segments and annotate each segment on the right hand side of the plot. I am following examples on plotnine online documentation, however the text on the right are being cutoff. I can display the text if I use…
vpk
  • 1,240
  • 2
  • 18
  • 32
1
vote
1 answer

Plotnine : How to create two legends on a single line

I am using plotnine to create a dual bar + line chart (see below). I would like the two legends to appear in a single line like the R example below. Can this be done with plotnine? Sample code below: plotnine code (what I have): import numpy as…
brb
  • 1,123
  • 17
  • 40