情节:如何更改图例中显示的行的大小?

苏里曼·谢里夫(Suliman Sharif)

我现在很难度过一段传奇,使传说变得更大。我已经用尽了文档,论坛,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)

在此处输入图片说明

vestland

The answer:

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))

The details:

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

情节:如何更改图形大小?

来自分类Dev

更改图表中的图例大小

来自分类Dev

更改图例中的字体大小

来自分类Dev

如何单独更改图例中的色线大小和形状大小?

来自分类Dev

如何更改图例中的行数?

来自分类Dev

情节:如何在情节快速的折线图中更改图例的变量/标签名称?

来自分类Dev

如何使用xlsxwriter更改图例字体大小-Python

来自分类Dev

如何设置海象形图的大小并更改图例位置?

来自分类Dev

情节:在绘制列时如何手动更改图例项?

来自分类Dev

如何更改图例的位置

来自分类Dev

如何更改图例栏和颜色以分别显示 Dataframe 中的每一行?(添加到 index_col)

来自分类Dev

在Python中更改图例散点图(气泡图)的图例标记大小

来自分类常见问题

如何在此ggplot中更改图例的标题

来自分类Dev

如何在R的Highcharter中更改图例的比例?

来自分类Dev

如何在此ggplot图表中更改图例?

来自分类Dev

如何在此ggplot中更改图例的标题

来自分类Dev

Highcharts:如何在图表导出中更改图例位置?

来自分类Dev

如何在dxChart中更改图例符号

来自分类Dev

如何更改图例框中符号/文本的位置?

来自分类Dev

是否可以在基数R中更改图例大小(无ggplot2)

来自分类Dev

如何更改图例点的颜色?

来自分类Dev

如何更改图例标记的颜色?

来自分类Dev

如何更改图例标签的 alpha?

来自分类Dev

在plotly-R中更改图例

来自分类Dev

在ggbiplot中更改图例标题

来自分类Dev

情节:如何更改情节表达图例的背景颜色?

来自分类Dev

如何在Github / Markdown中更改图像的大小?

来自分类Dev

如何防止轴更改图表中的间隔大小?

来自分类Dev

如何在C ++,SDL中更改图像大小

Related 相关文章

热门标签

归档