You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
facet_grid of data containing empty combinations (NaN) causes error #664
I have a set of data in one dataframe which has x and y values to be plotted in separate plots using x_plot and y_plot columns. The problem is that some of x_plot and y_plot combinations contain only np.nan values. However, I need a grid which will show all plots including empty ones for NaN combinations.
changed the title [-]facet_grid of data containing empty combinations (NaN) causes [/-][+]facet_grid of data containing empty combinations (NaN) causes error[/+]on Feb 17, 2023
import numpy as np
import pandas as pd
from plotnine import *
d = {
'x_plot':pd.Series(['XA','XA','XA','XA','XA','XA','XA','XA','XA','XB','XB','XB','XB','XB','XB','XB','XB','XB']),
'y_plot':pd.Series(['YA','YA','YA','YB','YB','YB','YC','YC','YC','YA','YA','YA','YB','YB','YB','YC','YC','YC']),
'x':[1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3],
'y':[5,6,7,np.NAN,np.NAN,np.NAN,1,2,3,4,5,6,np.NAN,np.NAN,np.NAN,1,2,3],
}
df = pd.DataFrame(data=d)
(
ggplot(df, aes(x='x', y='y'))+
geom_line()+
facet_grid('y_plot ~ x_plot', scales='free_y')
)
results in the following output:
ValueError: Axis limits cannot be NaN or Inf
My question is - is there a way to treat NA (or np.NAN) values in python using your lib in the same way as in R just leaving NA combinations of factors with empty plots?
Activity
[-]facet_grid of data containing empty combinations (NaN) causes [/-][+]facet_grid of data containing empty combinations (NaN) causes error[/+]has2k1 commentedon Feb 20, 2023
Please create a minimal reproducible example for the issue.
kasuskasus1 commentedon Feb 22, 2023
Running the following code in R:
results in the following plot:

At the same time identical code in python:
results in the following output:
My question is - is there a way to treat NA (or np.NAN) values in python using your lib in the same way as in R just leaving NA combinations of factors with empty plots?
Fix infinite x & y scale limits