Increase the size of legend symbol in plotly

I want to increase the size of legend symbol.

My Code
import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(
x=[1, 2, 3, 4, 5],
y=[1, 2, 3, 4, 5],
))

fig.add_trace(go.Scatter(
x=[1, 2, 3, 4, 5],
y=[5, 4, 3, 2, 1],
))

fig.update_layout(
legend=go.layout.Legend(
x=0,
y=1,
traceorder=“normal”,
font=dict(
family=“sans-serif”,
size=12,
color=“black”
)
)
)

fig.show()

Basically I want to increase the size of symbol i marked in the below plot. “The blue and red line” size

@maddy6 The marker size in legend is the same as the marker size set in the trace definition.

For this plot:

marker_size
I inserted in the your first trace above:

marker_size=10

while in the second trace:
marker_size=15

@empet I don’t want to increase the size of the series, I only want to increase the legend symbol size.

2 Likes

@maddy6 This is the only solution to increase the size of legend markers.

If you inspect the legend attributes running the following line of code:
help(go.layout.Legend) you’ll see that the only property referring to the marker size is:
legend_itemsizing.

legend_itemsizing='trace' (the default value) displays the marker size proportional to the trace marker_size (as in the image I posted above)

legend_itemsizing='constant' displays both markers of the same size no matter how the marker_size was set in trace definition. Usually it displays marker size equal to the largest marker_size among all traces.

3 Likes

@empet Actually I want to increase the image quality, So increased the Height and width, beacuse of that legends got super small. Do you know any option to increased the dpi option in plotly?

@maddy6 If you refer to the saved image resolution, then try experiment with different values of the write_image kwds:

import plotly.io as pio
help(pio.write_image)

Would be great if legends could be increased/decreased in size independently of the rest of the figure. I am currently exporting a PDF and then change the legend size with Adobe Illustrator.

I have not tried though > r - Change legend size in plotly chart - Stack Overflow

1 Like