I have a facet grid plot with two rows and three columns. I explicitly set the averaging function as “avg” :
histfunc="avg",
Yet the resulting output is a count. (when I explicitly set it as “count”, the graph does not change; same y values.)
The full code:
def histogram_facets(metric, nbins=2):
return px.histogram(
_ab_.sort_values(by="group", ascending=False), x=metric, color="group", nbins=nbins, facet_col="hour_segment", facet_col_wrap=3,
category_orders={"hour_segment": ["Middle of night", "Morning", "Lunch", "Afternoon", "Evening", "Night"] },
barmode="group",
histfunc="avg",
color_discrete_sequence=colors_lst,
facet_row_spacing=0.2, facet_col_spacing=0.08
)
Has anyone run into this problem before? Workarounds graciously accepted!
JuanG
2
Hi, Ben… Could you add full code, maybe with toy data if it is sensitive, to try for ourselves? The facet plot looks nice!
sure. Here is a full MRE (you should be able to download from that S3 bucket):
import pandas as pd
import numpy as np
repo = "s3://mre-examples/_ab_cleaned.csv"
_ab_ = pd.read_csv(repo)
import plotly.express as px
from plotly.offline import *
metrics_lst = ["converted", "user_journey_flag", "time_on_site", "bounce_rate", "pages_per_sesion"]
colors_lst = ["lightblue", "lightgreen"]
def histogram_facets(metric, nbins=2):
return px.histogram(
_ab_.sort_values(by="group", ascending=False), x=metric, color="group", nbins=nbins, facet_col="hour_segment", facet_col_wrap=3,
category_orders={"hour_segment": ["Middle of night", "Morning", "Lunch", "Afternoon", "Evening", "Night"] },
barmode="group",
histfunc="avg", # this is the finnicky param
color_discrete_sequence=colors_lst,
facet_row_spacing=0.2, facet_col_spacing=0.08
)
histogram_facets(metrics_lst[0])
Let me know if you’re able to find a workaround.