我想使用Fig.update_polars(angularaxis_color=color)或fig.update_polars(angleaxis=dict(color=color))用label_color对每个label_column进行着色,但我不能。
如何将每个column_label的颜色设置为与label_color相同的颜色?我希望aa用粉色写,bb用蓝色写,cc用粉色写,dd用蓝色写。
color_palette = {'Target': 'red', 'Current': 'blue'}
fig = px.line_polar(answers_avg,
r = 'value',
theta = 'label_column',
line_close = True,
line_dash = 'group')
for group, color in color_palette.items():
fig.update_traces(
line=dict(color=color),
selector=dict(name=group))
fig.show()
是的,只需通过
fig.layout.polar.angularaxis.color
更新轴标签的颜色即可。但这会更改该迹线的所有轴标签的颜色,因此如果您想要两种不同的颜色,那么您必须使用两条不同的迹线来绘制图表,每个迹线指定其轴标签颜色。
import plotly.express as px
import pandas as pd
color_palette = {'Target': 'red', 'Current': 'blue'}
answers_avg = pd.DataFrame([
dict(label_column='aa', label_color='pink', group='Current', value=3.),
dict(label_column='aa', label_color='pink', group='Target', value=4.538462),
dict(label_column='bb', label_color='blue', group='Current', value=2.818182),
dict(label_column='bb', label_color='blue', group='Target', value=4.5),
dict(label_column='cc', label_color='pink', group='Current', value=3.230769),
dict(label_column='cc', label_color='pink', group='Target', value=4.25),
dict(label_column='dd', label_color='blue', group='Current', value=2.923077),
dict(label_column='dd', label_color='blue', group='Target', value=4.583333),
])
fig = px.line_polar(answers_avg,
r = 'value',
theta = 'label_column',
line_close = True,
line_dash = 'group')
for group, color in color_palette.items():
fig.update_traces(
line=dict(color=color),
selector=dict(name=group))
fig.layout.polar.angularaxis.color = 'red'
fig.show()