I am looking for a way to get the count value of the largest bin in a histogram plot.
Background: I have a data set from a product test log that has columns for voltage readings of each unit at different test steps. I’m graphing a histogram plot with the voltages to look at the distribution.
I want to add a vertical line to show the lower and upper limits for the test step. I’m able to draw these lines with the correct x position but the ideal y position changes with each test step.
I am looking for a way to programmatically get the count value of the largest bin or dynamically draw a line that stops near the top of the graph.
I’ve tried to get the yaxis range value from the figure.layout but it is of “None” type since it was not explicitly set.
Using a fixed value of 2000 is too tall for this test step:
Using a fixed value of 2000 is too short for this test step:
#tick0, tickn and dtick are all dynamically calculated # tick0 = lower limit # tickn = upper limit # dtick = (tickn - tick0) /10 figHist = px.histogram(filtered_df, x=filtered_df.columns, marginal="rug") figHist.update_layout(xaxis=dict(title = 'Measurement', tickmode = 'linear', tick0 = tick0-dtick, dtick = dtick, range = [tick0-dtick,tickn+dtick])) # add lower limit line figHist.add_shape( type="line", x0=tick0, y0=0, x1=tick0, y1=2000, line=dict( color="red", width=4, dash="dot", )) # add upper limit line figHist.add_shape( type="line", x0=tickn, y0=0, x1=tickn, y1=2000, line=dict( color="red", width=4, dash="dot", ))