# Update xaxis with update button

**URL:** <https://community.plotly.com/t/update-xaxis-with-update-button/76992>\
**Category:** 📊 Plotly Python\
**Created:** [July 18, 2023, 10:50pm UTC](https://community.plotly.com/t/update-xaxis-with-update-button/76992 "2023-07-18T22:50:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KPinedaO](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@KPinedaO](https://community.plotly.com/u/KPinedaO)\
**Post date:** [July 18, 2023, 10:50pm UTC](https://community.plotly.com/t/update-xaxis-with-update-button/76992/1 "2023-07-18T22:50:57Z")

</div>

Hi, everyone.  
I´m new using plotly and I would like to know if someone can help.

I have a dataframe with dates. I want to create a bar plot in which I can show a count per each day, month and year. I shoe the count per day, and then I update the plot using two buttons.

```auto

import pandas as pd
import plotly.express as px
import datetime
import plotly

# Data creation
fechas = pd.date_range(start='2023-07-01', periods=10, freq='M')
ids = list(range(1, len(fechas) + 1))
data = {'Date': fechas, 'ID': ids}
df = pd.DataFrame(data)

#Creating fields to count
df["Year"] = pd.DatetimeIndex(df["Date"]).year
df["Month"] = df["Date"].dt.strftime('%Y/%m')
df["Day"] = df["Date"].dt.strftime('%Y/%m/%d')

#counting and converting to datetime
df_d = df.groupby(['Day'], as_index=False).count()
df_d['Day']= pd.to_datetime(df_d['Day'])

df_m = df.groupby(['Month'], as_index=False).count()
df_m['Month']= pd.to_datetime(df_m['Month'])
df_a = df.groupby(['Year'], as_index=False).count()
#df_a['Year']= pd.to_datetime(df_a['Year'])

dbar = px.bar(df_d,x='Day',y='Date')

dbar.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            direction="down",
            #bgcolor='Dark Blue',
            buttons=list(
                [
                    dict(
                        label="Day",
                        visible=True,
                        method="update",
                        args=[{"y": [df_d["Date"]]},
                        {"x": [df_d["Day"]]}]
                    ),
                    
                    dict(
                        label="Month",
                        visible=True,
                        method="update",
                        args=[{"y": [df_m["Date"]]},
                              {"x": [df_m["Month"]]}]
                    ),
                    
                    dict(
                        label="Year",
                        visible=True,
                        method="update",
                        args=[{"y": [df_a["Date"]]},
                              {"x": [df_a["Year"]]}]
                    )
            ]),
        ), dict(
            type="dropdown",
            direction="right"
    )
])

um = [{'showactive': True,
       'active': 0,
       'direction': 'right',
      'x': 1,'y': 1.1,}
      ]

dbar.update_layout(updatemenus=um)

dbar.show()

```

This is my code. Maybe it´s not the best approach but it´s working.

However, when I click the buttons the ticks in the xaxis doesn’t change.

Count each day works fine

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/a/6a9a74763f993758901a8405fd3e94c030a3bbbd.png)

But as you can see, the count each month and each year is wrong.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/8/1/81d0141b10d2ceacde590ce8de5e57cf58dcd24f.png)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/8/8/88fc6684d04b24dcd775b344c1ecc0235d3398f7.png)

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [July 19, 2023, 8:55am UTC](https://community.plotly.com/t/update-xaxis-with-update-button/76992/2 "2023-07-19T08:55:26Z")

</div>

HI @KPinedaO,

is your question how to change the axis ticks? If so, this could be helpful:

> **[Formatting](https://plotly.com/python/tick-formatting/)**
>
> Detailed examples of Formatting Ticks including changing color, size, log axes, and more in Python.

> **[Time](https://plotly.com/python/time-series/)**
>
> Over 21 examples of Time Series and Date Axes including changing color, size, log axes, and more in Python.
