Reputation: 91
currently I am trying to create a simple bar graph using Plotly express. My x and y parameters are both python lists and I am trying to change the axis names as well as the names on the legend. I have been reading through the documentation, but there doesn't seem to be an example of doing this with express. Does anyone know how to do this? My code is below:
import plotly.express as px
disbyyear = px.bar(x= years, y=repdis, title="Total Disbursments by Party")
disbyyear.add_bar(x=years, y=demdis)
#disbyyear.update_yaxes(y = 'Dollars USD')
disbyyear.update_layout(barmode = 'group')
disbyyear.show()
I want to for example change the 'y' on the left to say USD or something. Any help is appreciated thank you.
edit: thank yall for the axis naming, for the legend I am still struggling to understand the 'labels' parameter. from the documentation, you only seem to be able to edit the legend if you use a data frame , but not with lists
Upvotes: 9
Views: 24995
Reputation: 1763
You can use the labels
keyword argument.
disbyyear = px.bar(x= years, y=repdis, title="Total Disbursments by Party", labels={'x': 'Year', 'y':'Dollars USD'})
Upvotes: 5