Re: [问题] plotly如何用按键切换颜色参数抓取的字段

楼主: skyconquer (梅郭曲)   2020-06-07 21:53:18
※ 引述《jojojen (JJJ)》之铭言:
: 前辈大大们各位好,
: 以下这两张图是我想做出的效果
: https://imgur.com/qlrLBqu
: https://imgur.com/8AGG340
: 我用以下的程式码可以画出类似的接口
: 但点击按钮无法更新/改变图表:
: import plotly.express as px
: df = px.data.tips()
: fig = px.scatter(df, x="total_bill", y="tip", color="smoker")
: ## How to fix this part?
: fig.update_layout(
: updatemenus=[
: dict(
: type = "buttons",
: direction = "left",
: buttons=list([
: dict(
: args=["color", "sex"],
: label="sex",
: method="update"
: ),
: dict(
: args=["color", "smoker"],
: label="smoker",
: method="update"
: )])),])
: fig.show()
: ##
: 请问该如何修改,或用其他哪种套件能达到我想要的效果?
: 再请麻烦大大们指教 谢谢各位
我写了一个类似有类似效果的 Python code。
https://imgur.com/4Jrgra1
============================ 程式码在此 ===================================
import plotly.express as px
import plotly.graph_objects as go
import plotly
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="sex")
fig.add_trace(px.scatter(df, x="total_bill", y="tip", color="smoker").data[0])
fig.add_trace(px.scatter(df, x="total_bill", y="tip", color="smoker").data[1])
updatemenus=[dict(type = "buttons", direction = "left",
buttons=list([
dict(args=[{'visible': [True , True , False , False ]} ,],
label = "sex" , method="update"),
dict(args=[{'visible': [False , False , True , True ]} ,],
label = "smoker", method="update")
])),]
fig.update_layout(updatemenus = updatemenus,
legend_title_text='')
fig.show()
==============================================================================
不足的部份请其他高手补充。
作者: jojojen (JJJ)   2020-06-07 23:45:00
感谢大大 我研究看看!!!
楼主: skyconquer (梅郭曲)   2020-06-08 21:46:00
不会 :)

Links booklink

Contact Us: admin [ a t ] ucptt.com