How To Plot Sorted Barplot In Plolty3.10
I have been trying to plot sorted barplot in plotly for some stores sales data, but whatever I try it gives me the unsorted data. How to plot the sorted barplot using plotly. NOTE:
Solution 1:
The correct key to use for this is layout.xaxis.categoryorder
, with the value "total ascending"
, but it only applies when the layout.xaxis.type
is "category"
. This happens automatically if your x
array contains strings, but if your x
contains only numbers you'll have to set it manually.
Here is a version of your barplot
function as recommended:
def barplot(x,y):
data = [go.Bar(
x=x,
y=y,
marker={
'color': y,
'colorscale': 'Reds'
}
)]
layout = {
'xaxis': {
'tickvals': x,
'ticktext': ['store ' + str(i) for i in x],
'tickangle': 40,
'type': "category",
'categoryorder': 'total ascending'
}
}
fig = go.FigureWidget(data=data, layout=layout)
return iplot(fig)
Post a Comment for "How To Plot Sorted Barplot In Plolty3.10"