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.

plotnine
Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

Is there a way to ensure the label for 0 has no decimal places in plotnine

I am producing a bunch of plots using the Plotnine library in Python. Sometimes, when I am using facet_wrap, two adjacent plots will have the upper and lower x limits run together. That is, say the ...
CopyOfA's user avatar
  • 829
0 votes
2 answers
49 views

Plotnine legend justified to left

I cannot justify the legend to the left despite adding legend_box_just="left". I'm using Plotnine version 0.13.0 with Python 3.11. Code: df = pd.DataFrame({ 'Date': pd.date_range(start=&...
Jon Aldekoa's user avatar
0 votes
2 answers
90 views

No module named 'matplotlib.typing'

I am receiving an error message: ModuleNotFoundError: No module named 'matplotlib.typing' with this bit of code: from plotnine import * (ggplot(the, aes(x='Trial', y='Weights', colour='Cues')) + ...
striatum's user avatar
  • 1,548
0 votes
1 answer
76 views

Problem using the `geom_col` in plotnine with Linux (Ubuntu 22.04.3 LTS) and Windows

When I try to run the following reproducible example using plotnine I get an error: import pandas as pd from plotnine import ( ggplot, aes, geom_col ) from plotnine.data import mtcars df ...
luifrancgom's user avatar
1 vote
1 answer
86 views

Add regression line equation to facet_wrap in PLOTNINE

I'm trying to add equation of the linear equation fitted to the plotted data. I have used geom_smooth and method 'lm' with formula = 'y~x'. add eq to single plot shows how to it to a single plot, ...
etikafh's user avatar
  • 13
0 votes
0 answers
49 views

Can i over draw more elements into a canvas in tkinter?

i want to know if there is a way to draw more elements into a canvas in tkinter. My goal is to display in a canvas a trajectory made with plotnine and two circles as the boundaries like in the ...
Ale_7's user avatar
  • 1
0 votes
1 answer
37 views

Plotnine graphing melted dataframe as 2 separate lines

I am trying to graph a melted dataframe, as shown here: SleepDay category value 0 4/12/2016 12:00:00 AM TotalMinutesAsleep 750 1 4/13/2016 12:00:00 AM ...
Nikshith Konnuru's user avatar
0 votes
1 answer
42 views

How to put errorbars on only one group in plotnine?

How do I put error bars on only one group in plotnine? For example, say I have a dataframe: dat = pd.DataFrame(data={"Type":["A","A","B","B"],"x&...
Wyatt's user avatar
  • 3
3 votes
1 answer
290 views

plotnine change default colormap

Is there a way to change the default colormap in plotnine to a custom colormap? I like to avoid adding something like + scale_color_manual(custom_palette) to all my ggplot figures. I know how to ...
dsforecast's user avatar
1 vote
1 answer
85 views

ValueError: Wrong number of items passed 2, placement implies 1 when graphing a facet_grid with plotnine

I have the following Dataframe built with Pandas: SampleSize Mean StandardDeviation 0 5 0.134151 0.739142 1 25 -0.111257 1.154803 2 45 -0....
Nikshith Konnuru's user avatar
0 votes
1 answer
138 views

Cant save fig with plotnine

I have a plot that I am trying to save with plotnine. w = 10 h = 5 p9.ggsave(heatmap,plotName, width=w, height= h, dpi=300, limitsize=False) For some reason I keep getting the following error: ...
Paulina Stehlik's user avatar
1 vote
2 answers
549 views

Plot multiple lines with plotnine

Please consider this code for plotting multiple lines: import numpy as np import pandas as pd import matplotlib.pyplot as plt x = [1,2,3] y = [ [30, 4, 50], [300,400,500], [350,450,550] ] plt.plot(x, ...
Antonio Sesto's user avatar
0 votes
2 answers
212 views

ImportError: cannot import name 'factor' from 'plotnine'

I try to use the factor option in plotnine. My code is: from plotnine import ggplot, aes, geom_bar, factor I get this error. ImportError Traceback (most recent call last)...
Ralf Schenke's user avatar
1 vote
1 answer
185 views

plotnine: how to modify colormaps

Please consider this code (it is an example in the doc): import pandas as pd import numpy as np from plotnine import * df = pd.DataFrame({ 'variable': ['gender', 'gender', 'age', 'age', 'age', '...
Antonio Sesto's user avatar
1 vote
2 answers
76 views

Using manual colors for ggplot in Python

I'm trying to assign custom color palette to the plot. Values can be between 0 and 4 and for values 0-1, 1-2, 2-3, 3-4 I'd like to assign given color (e.g. "#C5FABE", "#F5D562", &...
Dominik Roszkowski's user avatar
0 votes
0 answers
32 views

plotnine geom_smooth formula exp not defined

I'm using + geom_smooth(method="lm", formula= ("y ~ exp(x)")) in plotnine, but I got the following error: NameError: name 'exp' is not defined I haven't used ggplot in R, but I ...
guckmalmensch's user avatar
0 votes
1 answer
152 views

How can I fix the facet (subplot) spacing for plotnine?

Can someone help me determine why these images are coming out different from one another? I am trying to re-generate a plot I made with plotnine. Unfortunately, running the same code seems to generate ...
Jay Bundy's user avatar
0 votes
0 answers
161 views

Plotnine in Databricks

I am using Databricks, and when trying to display a plot made with plotnine, every time I run any cell, the plot appears on the output multiple times. My code is the next one: my_plot = (ggplot(df, ...
Nacho Arévalo Evans's user avatar
0 votes
1 answer
229 views

Plotnine: How to use geom_col and geom_text to display mean by group

I have a dataset that I am using geom_col to visualize using stat='summary'. I can't quite figure out how to use geom_text() to display the mean values. Here is the code and plot I am able to produce: ...
Larry Burholme's user avatar
0 votes
1 answer
44 views

How to create bar chart with geomean, mean, max and min from data using Plotnine

How to create bar chart with gmean, mean, max and min stats for each category. For the data below, X B Y A1 b1 4 A1 b2 2 A1 b3 3 A1 b4 8 A2 b1 7 A2 c1 10 A2 c2 8 A2 b3 7 A3 b4 10 A3 b5 9 ...
kanna's user avatar
  • 1,432
0 votes
1 answer
60 views

Is there an equivalent to %+% for plotnine?

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....
Jake Fisher's user avatar
  • 3,260
0 votes
1 answer
174 views

Getting ggplot (python) error NameError: name 'ggplot' is not defined

I am trying to get a graph, but I keep receiving an error saying that ggplot is not defined. i have downloaded the plotnine library from plotnine import * from plotnine.data import diamonds import ...
Lee's user avatar
  • 1
0 votes
0 answers
35 views

Create histogram with frame in plot nine

I would like to create a histogram with a frame, where not all bars have a frame, but over the collected bars. I first had the idea to create a geom_histo with color, and then to create a geom_histo ...
Rauschy's user avatar
1 vote
1 answer
98 views

plotnine:: is there a better way to refer args of facet_wrap in after_stat

I wants to show percentages for bar plots using plotnine with facet_wrap and stat = 'count'. (Of course I can do it with preparation of values and stat = 'identity', but I want to avoid it.) When I ...
cuttlefish44's user avatar
  • 6,665
0 votes
1 answer
86 views

Custom Sorting gglot2 in python

I am working on ggplt visualization, which plotting countries total expenditure from the highest to the lowest. Since there are many small values, I am aggregating several small categories into the &...
diana's user avatar
  • 3
0 votes
0 answers
420 views

Problem with statsmodels when importing plotnine and other moduels

I'm having a problem importing the modules plotnine and binsreg. When I try to import them I get the error ImportError: cannot import name '__version__' from 'statsmodels._version' (/usr/local/lib/...
gfgm's user avatar
  • 3,627
0 votes
2 answers
197 views

Plot multiple dataframe in a plot with facet_wrap

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 ...
kaixas K's user avatar
  • 111
0 votes
2 answers
717 views

Plotnine: color scale and legend issues

I'm trying to make some plots with plotnine. I have clustered points into several clusters labeled 0 through 6. (but this range may change depending on the number of clusters in the future). My goal ...
Ian Dryg's user avatar
1 vote
1 answer
138 views

How to replicate a table from R to python using Matplotlib or Plotly

I am trying to replicate a table, which is currently produced in R, in python implementing plotnine library. I am using facet.grid with two variables (CBRegion and CBIndustry). I have found a similar ...
Carpe Diem's user avatar
2 votes
1 answer
920 views

Plotnine : Secondary y-axis (dual axes)

I am using python's wonderful plotnine package. I would like to make a plot with dual y-axis, let's say Celsius on the left axis and Fahrenheit on the right. I have installed the latest version of ...
brb's user avatar
  • 1,129
1 vote
1 answer
835 views

Plotnine (ggplot) : Set the direction legend elements are populated when specifying n rows

I am doing this in plotnine, but hoping ggplotters can assist as well. Consider the following plot: df = pd.DataFrame({ 'date' : pd.date_range(start='30/09/2019', periods=11, freq='Q').repeat(6), ...
brb's user avatar
  • 1,129
0 votes
2 answers
89 views

Plotnine (ggplot) : Add whisker to end of geom_segment

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'], ...
brb's user avatar
  • 1,129
0 votes
0 answers
645 views

Plotnine (ggplot) : Remove some elements from a legend

I am coding in python's plotnine, but hoping that R ggplotters may also be able to offer a solution. Consider the below plot. It has two states, 'pass' and 'fail' and I want to highlight the 'fail' ...
brb's user avatar
  • 1,129
1 vote
1 answer
1k views

Python ModuleNotFoundError: No module named 'patsy' when using ggplot

I am attempting to run the following code to plot the explained variance after applying PCA on my dataframe: (ggplot(pcaDF, aes(x = "Principal Components", y = "expl_var")) + ...
sums22's user avatar
  • 1,953
2 votes
1 answer
431 views

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 * ...
filups21's user avatar
  • 1,743
4 votes
3 answers
2k views

plotnine is broken with matplotlib==3.6

I am getting the following error with plotnine==0.9 and matplotlib==3.6. File "D:\Python\Python310\lib\site-packages\plotnine\stats\stat_density_2d.py", line 3, in <module> import ...
Haoran Yi's user avatar
  • 547
0 votes
1 answer
2k views

How do I set scaling for axes using plotnine?

I am using plotnine library to visualise data. I use for loop to create graphs for different groups of my dataset. Range of groups is different (varies from few tens to tens of thousands). Here my ...
quakenstein's user avatar
0 votes
0 answers
197 views

Can python plotnine draw charts on web application?

I'm learning fastapi web framework for my data science visualization project. I know python plotnine is usually used on notebook or something. Can I use plotnine to draw any ggplot2 charts on the web ...
Jun Jang's user avatar
0 votes
1 answer
114 views

labeling Confidence interval and coefficient using ggplot in Pandas

I tried to label coefficient and Confidence interval using the following code: pp =p.ggplot(leadslags_plot, p.aes(x = 'label', y = 'mean', ymin = 'lb', ymax = 'ub')) +\ ...
Jui Sen's user avatar
  • 377
1 vote
1 answer
360 views

Python translate matplotlib to a plotnine chart

I am currently working through the book Hands On Machine Learning and am trying to replicate a visualization where we plot the lat and lon co-ordinates on a scatter plot of San Diego. I have taken the ...
John Smith's user avatar
  • 2,676
1 vote
0 answers
326 views

The PlotnineError: "For loess smoothing, install 'scikit-misc'"

When I try to fit a curve with plotnine,it had a error that couldn 't run That's my code import pandas as pd import numpy as np from plotnine import * import skmisc df=pd.read_csv('Scatter_Data.csv') ...
ほしの凉's user avatar
0 votes
0 answers
200 views

Pyscript and Plotnine

I am trying to use Plotnine: https://plotnine.readthedocs.io/en/stable/index.html with PyScript. My code looks as follows: <html> <head> <link rel="stylesheet" href="...
Aku-Ville Lehtimäki's user avatar
1 vote
2 answers
814 views

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', ...
brb's user avatar
  • 1,129
0 votes
1 answer
229 views

How to plot density horizontally in plotnine?

Running the code: from plotnine import * import numpy as np import pandas as pd df = pd.DataFrame({'values': np.random.normal(0,10,1000), 'group': ['a']*500 + ['b']*500}) # plot = ( ggplot(df, ...
catastrophic-failure's user avatar
2 votes
1 answer
706 views

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%...
brb's user avatar
  • 1,129
1 vote
1 answer
824 views

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....
Mathijs's user avatar
  • 19
1 vote
1 answer
665 views

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 ...
catastrophic-failure's user avatar
2 votes
1 answer
273 views

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 ...
S -'s user avatar
  • 359
-1 votes
1 answer
391 views

module 'plotnine' has no attribute 'ggplot_build'

p3 = (p9.ggplot(data = df, mapping = p9.aes(x = 'gross_power', y = 'temp_drop_a',show_legend=False, alpha = 0.7)) + p9.geom_jitter() + p9.geom_smooth(se= 'F',method="lm", colour = 'red')) ...
Heidi's user avatar
  • 11
1 vote
1 answer
330 views

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 ...
Heidi's user avatar
  • 11