我现在很难度过一段传奇,使传说变得更大。我已经用尽了文档,论坛,github问题,但一无所获。开始认真地考虑并不是那么出色的软件。
我创建了此图:
我想使Trial 1,Trial 2和Trial 3的图例中的行变大。我可以使用它们的api来使字体变大,但我看不到图例行,因此想知道它是否是possibe。
这是一些代码:
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)),
)
玩着项目大小,也一无所获。有人对如何实现这一目标有任何想法吗?
更新:
Based on the answer below I was able to get the line thicker but there is a limit. And attached is the limit of thickness I believe it to be (don't know the exact size)
Depending on how you've set up your figure, you can use:
fig.update_layout(legend=dict(itemsizing='constant'))
Or:
fig.update_layout(legend=dict(itemsizing='trace'))
fig.update_traces(line=dict(width=12))
You seem to have opted for very thin lines when setting up the figure. You can "detach" the width of the lines in the legend from the width of the trace lines using:
fig.update_layout(legend=dict(itemsizing='constant'))
Since you haven't produced a runnable code snippet, I'll show the effect using data from px.data.gapminder()
.
Plot 1 - Without fig.update_layout(legend=dict(itemsizing='constant'))
Plot 2 - With fig.update_layout(legend=dict(itemsizing='constant'))
Your third option is to set fig.update_layout(legend=dict(itemsizing='trace'))
and then increase the line width for the traces and the legend using, for example, fig.update_traces(line=dict(width=12))
:
Plot 3 - With 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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句