-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Changing the y label for histogram in plotly express does not work #2876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Keeps happening in 4.14.3 I fixed it a little bit with fig = px.histogram(
n_orders, labels={"value": "# Pedidos", "count": "# Clientes"}
).update_layout(
title={"text": "Numero de pedidos por cliente", "x": 0.5}, yaxis_title="# Clientes"
)
fig.show() |
Keeps happening |
Still happening with 5.6.0 |
you need to change it using |
@nicolaskruchten, I am experiencing this issue today. In our project, all texts need to be localized, so we cannot rely on auto-generated labels such as "sum of" or "probability". The following code produces the correct chart, but the aggregate category label is prefixed with "sum of" in both the axis label and hover text. px.histogram(
chart_data,
x="role_name",
y="total_minutes",
color="work_type",
labels={
# notice here the use of _("") localization function
"role_name": _("Caregiver role"),
"total_minutes": _("total minutes"),
"work_type": _("Type of work"),
},
) The desired output above would be that the y-axis label and hover text would just be "total minutes" rather than "sum of total minutes", the latter of which we cannot localize. |
Given the ambiguity of the original request, I will gladly open a second issue related to changing the y-axis label and hover text, if needed. |
@brylie this is a bit of a different issue but I may as well respond here so folks scrolling through find it ;) There's no set of arguments you can pass to PX to localize these "sum of" and "probability" strings unfortunately, so you'll have to mutate them explicitly with something like the code below. For completeness, you'll need to localize not only the field names as you have done above, but also the values within the colums ("Sat", "Sun" in my example, and "Nurse" in your example above), for which there is no Plotly functionality, and you'll need to do in the underlying data. import plotly.express as px
fig = px.histogram(px.data.tips(), x="day", y="total_bill")
fig.for_each_trace(lambda t: t.update(hovertemplate=t.hovertemplate.replace("sum of", "somme de")))
fig.for_each_yaxis(lambda a: a.update(title_text=a.title.text.replace("sum of", "somme de"))) |
@nicolaskruchten, thank you for your quick response and examples. The example seems like a good temporary work-around while exploring the underlying issue of prepending English text to chart axis labels and hover texts. In my case, I'd rather the text weren't prepended at all, since my axis label ("total minutes") is correct. |
Co-authored by: Nicolas Kruchten <[email protected]> Related to plotly/plotly.py#2876 (comment) Related to plotly/plotly.py#3694
Co-authored-by: Nicolas Kruchten <[email protected]> Related to plotly/plotly.py#2876 (comment) Related to plotly/plotly.py#3694
Co-authored-by: Nicolas Kruchten <[email protected]> Related to plotly/plotly.py#2876 (comment) Related to plotly/plotly.py#3694
Co-authored-by: Nicolas Kruchten <[email protected]> Related to plotly/plotly.py#2876 (comment) Related to plotly/plotly.py#3694
@nicolaskruchten, thank you for the examples, I have made small modification to the same code added animation_frame, before the play button is clicked yaxis and hovertext has no "sum of" text but once played we can see hovertext adds again sum of. import plotly.express as px |
Hi! I've been having the same issue. With the following code it showed the next chart:
And finally I've been able to fix it with the following code:
Hope it helps! |
Hi I am using plotly express to plot a histogram.
The y label is shown as count, I want the y label to be called probability.
I tried passing
labels={'diag': 'cosine similarity', 'count': 'probability'}
but that doesn't work? How do I change the y label ?The text was updated successfully, but these errors were encountered: