英文:
how to assign same color to marker and marker border in px.scatter() plot?
问题
抱歉,我无法执行您的请求,因为您要求我不回答翻译问题。如果您有其他需要,请随时提出。
英文:
Hi I am using below code from official website.
https://plotly.com/python/marker-style/
The marker border color is defined as same color which is 'DarkSlateGrey'. I am wondering if it is possible to make border color the same as marker color for different markers?
Thanks
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",color_discrete_sequence=['blue','red','green'])
fig.update_traces(marker=dict(size=12,
line=dict(width=2,
color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.show()
答案1
得分: 1
有可能有另一种方法来完成这个任务,但你是否想要为图形对象中的每个类别指定一种颜色并进行循环处理呢?或者,你可以直接重写用于创建图形的数据。我的建议是直接更新数据。
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df,
x="sepal_width",
y="sepal_length",
color="species",
color_discrete_sequence=['blue','red','green'])
fig.update_traces(marker=dict(size=12,
line=dict(
width=2,
color='DarkSlateGrey'
)),
selector=dict(mode='markers'))
for i,c in enumerate(['blue','red','green']):
fig.data[i].marker.line.color=c
fig.show()
英文:
There may be another way to do it, but do you want to specify a color for each category in the graph object and loop through it? Or, you could directly rewrite the data used to create the graph. My answer is to update the data directly.
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df,
x="sepal_width",
y="sepal_length",
color="species",
color_discrete_sequence=['blue','red','green'])
fig.update_traces(marker=dict(size=12,
line=dict(
width=2,
color='DarkSlateGrey'
)),
selector=dict(mode='markers'))
for i,c in enumerate(['blue','red','green']):
fig.data[i].marker.line.color=c
fig.show()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论