GOAL & CONTENT
Using python plotly.express, I have a slider that allows me to “slide” through the different dates of my data. Therefore, I can have one graph for the data with the same date and then slide to another date and have another graph which contains the new data corresponding to the slider date.
If it’s hard to understand please see the picture below (it is taken from internet but shows a slider which slides through different years) :
So my goal is to have a slider that shows me on the graph the data corresponding to the current slider date.
PROBLEM
My problem is that when I use the slider, it does show the correct data points but the x-axis and the y-axis do not change ranges. In short, it does not auto scale the ranges correctly when sliding.
As my x-axis, I have categorical variables (names) and y-axis is the price. So, when I slide to another date, I do have the points changing but the categories stay as the initial categories. It does the same thing for y-axis.
As an example, if I slide to date X I will have as my x-axis range A, B and C each with y-axis between 1-3$. However, if I slide to date Y, the data will change correctly but the ranges do not scale to the new data. Therefore, for date Y I will not see any points as the category will stay as the initiale ones A,B,C instead of showing C,E,F on x-axis. Moreover, for the y-axis, it will still only show from range 1 to 3$ instead of scaling to the new range 3-130 for example.
WHAT I TRIED
I seem to have the same problem as this person but there was no answer. I tried what she tried as well: https://community.plotly.com/t/auto-scale-plotly-express/33364 I wanted to try this aswell but I do not know where to place it in my code correclty: https://community.plotly.com/t/solved-how-to-progamatically-autoscale-plot/3278
MY CODE
This is my code for now:
data.columns = ['price', 'category', 'date']
data = data.sort_values(by=['date', 'price'])
fig = px.scatter(data, x = "category", y = "price", animation_frame="date")
fig.update_layout(
yaxis_title="Price (€)",
)
fig['layout']['updatemenus'][0]['pad']['t'] = 180
fig['layout']['sliders'][0]['pad']['t'] = 200
fig.write_html("/home/**/Desktop/1.html", auto_play=True)
Ihope I was clear enough. Please let me know if you need any extra information. Any ideas or tips is welcome :)