My input:
df=(pd.DataFrame({'label_color':['white','white','cyan','cyan','cyan','cyan','white','white'],
'label_quality':['white','white','red','green','green','red','white','white'],
'label':['foo','foo','foo','foo','foo','foo','foo','foo']}))
I trying figure plot with plotly there looks like this:
(Sorry I did it in powerpoint) Let me explain what I want: "One column" will be label color
and "Second column" will be label_quality
, where x.axis
is df.index
and correlated position columns with order of index. Also y.axis
is just name of label. And colors
is values from df columns["label_colors ","label_quality"]
Here my unsuccessfully plot:
fig = px.bar(test, x =['label_color','label_quality'], orientation='h', barmode='group', color=list(test['label_color']))
fig.show()
The data you presented does not match the content of the x-axis of the graph, but in order to achieve what you want, you need to add values for each of them, because you cannot draw a graph with just the color names. In addition, after completing the horizontal bar graph, I have updated the list of columns with the desired colors. The color of the border is changed to determine whether it is blank or white with respect to color. Depending on the purpose of the graph, a Gantt chart may be preferable to a timeline.
df['color_value'] = 1
df['quality_value'] = 1
fig = px.bar(df, y=['color_value','quality_value'],
x=[1]*len(df),
orientation='h',
barmode='group',
template='plotly_white')
fig.data[0]['marker']['color'] = df['label_color'].tolist()
fig.data[1]['marker']['color'] = df['label_quality'].tolist()
fig.update_traces(marker_line_color='rgb(8,48,107)')
fig.update_layout(showlegend=False, yaxis_title='foo', xaxis_title='')
fig.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.