plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Histogram should not prepend any text to axis and hover labels (e.g. "sum of ...")

Open brylie opened this issue 3 years ago • 3 comments

Split from #2876

We need to localize all texts in our project. So, we can't rely on auto-generated, English labels such as "sum of" or "probability."

Issue

The following code produces the correct chart. However, the auto-generated phrase "sum of" appears in 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"),
    },
)

image

image

Expected outcome

The desired output would be that the y-axis label and hover text would be "total minutes" rather than "sum of total minutes," the latter of which we cannot localize. Specifically, when labels are defined for chart dimensions, the aggregation type ("sum of" in this case) should not be prepended to the text, since the content and data language may not be English.

brylie avatar Apr 27 '22 18:04 brylie

This requests makes sense but can't make it the default behaviour as 1) it would be a backwards-incompatible change and 2) when doing exploratory analysis it's extremely important that the Y axis correctly displays the operation being done on the data.

I would be open to a pull request which added a flag to all PX functions that accept histnorm to suppress this output.

nicolaskruchten avatar Apr 27 '22 19:04 nicolaskruchten

Hi, Brylie, I have encountered the same problem, have you found a way to remove the "sum of" from the y-axis label?

Mingmei2020 avatar Jun 13 '22 02:06 Mingmei2020

I was able to remove the text using the example from @nicolaskruchten

https://github.com/plotly/plotly.py/issues/2876#issuecomment-1111339561

brylie avatar Jun 13 '22 08:06 brylie