I trying to update the xaxis_title_text
(update_layout) and the tickvals
and ticktext
(update_xaxes) when the dropdown value changes.
I have tried to adapt the Plotly examples (link) and this answer, but I am stuck with the axes updates. In Figures 1 and 2, we can see from Figure 1 to Figure 2 that the axes do not update when the dropdown changes. Tkx for the help with that.
Figure 1
Figure 2
<>/strong>:
import pandas as pd
import numpy as np
import plotly.graph_objects as go
### My df has more than 1,5M rows with 79 columns. Each column may vary the scale of the number.
### E.g.: Age, weight, income, etc aren t normalized.
df = pd.DataFrame() # any dataframe to compute a histogram
num_cols = df.columns
def compute_bins(x, bins, return_var):
hist, bins_edges = np.histogram(x, bins=bins)
bins_text = [f"({np.round(bins_edges[i],2)}, {np.round(bins_edges[i+1],2)}]" for i in range(len(bins_edges)-1) ]
if return_var == h :
return hist
else:
return bins_text
hist = compute_bins(x=df[x_title].values, bins=10, return_var= h )
hist = compute_bins(x=df[x_title].values, bins=10, return_var= b )
fig = go.Figure(go.Bar(x=np.array(range(len(bins_text))), y=hist))
my_buttons = [dict(
mehotd= update ,
args=[{"y": [ compute_bins(x=df[x_title].values, bins=10, return_var= h ), underfined ]
"x": [ compute_bins(x=df[x_title].values, bins=10, return_var= h ), underfined ]}
],
label = c
) for k, c in enumerate(num_cols)]
fig.update_axes(tickvals==np.array(range(len(bins_text))), ticktext=bins_text)
fig.update_layout(bargap=0, xaxis_title_text=x_title, yaxis_title_text= Count ,
updatemenus=[dict(
active=0,
x=0,y=1.2,
xanchor= left ,
yanchor= top ,
buttons=my_buttons
)]
)