[英]Plotly: How to change the size of the lines displayed in the legend?
在 plotly 中,我很難讓傳奇變得更大。我已經用盡了文檔、論壇、github 問題,但一無所獲。 開始覺得 plotly 不是什么好軟件。
我創建了這個圖表:
我想在 Trial 1、Trial 2 和 Trial 3 的圖例中使線條更大。我可以使用他們的 api 使字體更大,但我沒有看到對圖例線條的引用,現在想知道它是否可行。
這是一些代碼:
fig.update_layout(
title_text="Dipole Moment X (0 V/nm)",
title_font=dict(size=44, family='Arial'),
template='simple_white',
xaxis_tickformat = 'i',
bargap=0.2, # gap between bars of adjacent location coordinates,
legend=dict(
orientation="h",
yanchor="bottom",
y=1.02,
xanchor="right",
x=1,
font = dict(family = "Arial", size = 60),
bordercolor="LightSteelBlue",
borderwidth=2,
itemsizing='trace'
),
legend_title = dict(font = dict(family = "Arial", size = 60)),
)
玩弄了 itemsizing 也一無所獲。 任何人都知道如何做到這一點?
更新:
根據下面的答案,我能夠使線條變粗,但有一個限制。 附件是我認為的厚度限制(不知道確切的尺寸)
根據您設置圖形的方式,您可以使用:
fig.update_layout(legend=dict(itemsizing='constant'))
要么:
fig.update_layout(legend=dict(itemsizing='trace'))
fig.update_traces(line=dict(width=12))
在設置圖形時,您似乎選擇了非常細的線條。 您可以使用以下方法從跟蹤線的寬度中“分離”圖例中的線寬:
fig.update_layout(legend=dict(itemsizing='constant'))
由於您尚未生成可運行的代碼片段,我將使用來自px.data.gapminder()
的數據展示效果。
Plot 1 -沒有fig.update_layout(legend=dict(itemsizing='constant'))
Plot 2 -使用fig.update_layout(legend=dict(itemsizing='constant'))
您的第三個選擇是設置fig.update_layout(legend=dict(itemsizing='trace'))
然后使用例如fig.update_traces(line=dict(width=12))
:
Plot 3 -使用fig.update_layout(legend=dict(itemsizing='trace'))
import plotly.express as px
df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country')
fig.update_layout(showlegend=True)
fig.update_layout(legend = dict(bgcolor = 'yellow'))
#fig.update_layout(legend=dict(itemsizing='constant'))
fig.update_layout(legend=dict(itemsizing='trace'))
fig.update_traces(line=dict(width=12))
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.