1

I want to set a fitting x and y axis name on my px. box() graph, the problème is that the automatic name doesn't disappear:

fig1 = px.box(birth_price_box1["price"],
             log_x=False,
             color = birth_price_box1["birth"])

fig1.update_traces(hoverinfo='skip', 
                  hovertemplate = None
                 )

fig1.update_layout(
    title={
        'text': "montant total des achats en fonction de l'année de naissance",
        'y':0.95,
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'
    },
    
    xaxis_title = "année",
    yaxis_title = "montant total (€)",
)

fig1.show()

the result : boxplot

enter image description here

vestland
  • 55,229
  • 37
  • 187
  • 305

1 Answers1

0

Building on this example, you can just include:

fig.update_xaxes(title_text = 'New x-axis title')

Or in your specifc example, replace:

xaxis_title =  "année"

with:

xaxis_title_text =  "année"

Plot

enter image description here

Complete code:

import plotly.express as px

df = px.data.tips()

fig = px.box(df, x="day", y="total_bill", color="smoker")
fig.update_traces(quartilemethod="exclusive") # or "inclusive", or "linear" by default
f = fig.full_figure_for_development(warn=False)

fig.update_xaxes(title_text = 'New x-axis title')
fig.show()
vestland
  • 55,229
  • 37
  • 187
  • 305
  • 1
    Thanks vestland, I tried but doesn't seem to work, but using your way to call the graph: px. box(df, x="day", y="total_bill", color="smoker") and not px.box (df["day"], color=df["smoker"]) Everything seems to work properly – Corentin Metral Feb 17 '22 at 11:15
  • @CorentinMetral `fig.update_xaxes(title_text = 'New x-axis title')``should work either way. If it doesn't,, then there's something funky about the way you've set up the figure. In either case, do you have what you need now? – vestland Feb 17 '22 at 11:26
  • sorry I'm steel not familiar with notif of stack overflow and didn't see your reply all good, I got what I needed thanks a lot. – Corentin Metral Feb 18 '22 at 10:08