0

I try to make a stacked bar plot with plotly express. The only problem is that I'm not able to remove the '=' sign from 'region_txt' which I use to instantiate the variable 'color' with. Now my legend shows the '=' sign in front of the region names. Is there any way to remove this '=' sign? Our data looks partly like this:

data example

import plotly.express as px

fig = px.bar(df_agg, x='iyear', y="count", color='region_txt',
              labels={
                     "iyear": "Jaar",
                     "count": "Hoeveelheid aanslagen",
                     "region_txt": "" 
                    },
             title="terroristische aanslagen per jaar per regio", )

fig.update_layout(legend=dict(
    yanchor="top",
    y=0.99,
    xanchor="left",
    x=0.01,
    bgcolor="rgba(0,0,0,0)",
))
fig.show()

The legend

Julius
  • 37
  • 4
  • Since the data is not presented, this may be an issue before graphing. try this:`df_agg['region_txt'].str.replace('=','')` – r-beginners Jun 10 '21 at 12:54
  • our data itself has not this value, it is the title of the column that is causing the problem, I have added an example of our data table – Julius Jun 10 '21 at 13:00
  • I tried your code since you presented the data. In my environment (plotly 4.14.3), '=' does not appear in the legend. – r-beginners Jun 10 '21 at 13:18

0 Answers0