Re: [問題] plotly如何用按鍵切換顏色參數抓取的欄位

看板Python作者 (梅郭曲)時間5年前 (2020/06/07 21:53), 編輯推噓1(101)
留言2則, 2人參與, 5年前最新討論串2/2 (看更多)
※ 引述《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() ============================================================================== 不足的部份請其他高手補充。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 110.50.146.118 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1591538000.A.25F.html

06/07 23:45, 5年前 , 1F
感謝大大 我研究看看!!!
06/07 23:45, 1F

06/08 21:46, 5年前 , 2F
不會 :)
06/08 21:46, 2F
文章代碼(AID): #1UtF5G9V (Python)
文章代碼(AID): #1UtF5G9V (Python)