Graph size (Size of Legends, spacing of title from axis)

Hi team,

I need your help in setting the correct graph size of my chart.

  1. How can I scale the legends? I tried setting the font size=5 but the legend size does not adjust:

fig.update_layout(legend_orientation=“h”,font=dict(
family=“sans-serif”,
size=5,
color=“black”
),legend= {‘itemsizing’: ‘trace’})

  1. How can I reduce the spacing between the title and y-axis?

Thanks for your help!

My code for the layout:

fig.update_layout(
title={‘text’:‘6. Russell 1000 Predicted Risk’,
‘y’:0.9,
‘x’:0.5,
‘xanchor’: ‘center’,
‘yanchor’: ‘top’ },

yaxis=dict(
    title='US4 Risk',
     ticksuffix="%",
),
 paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',

)

fig.update_yaxes(title=‘Return’,
ticksuffix="%",secondary_y=True)
fig.update_layout(legend_orientation=“h”,font=dict(
family=“sans-serif”,
size=5,
color=“black”
),legend= {‘itemsizing’: ‘trace’})

Hi @vgelis,

To change the legend font property you need to set it inside the legend object vs. set it globally. To set the position of the axis title see this tutorial: https://plot.ly/python/axes/#set-axis-title-position:

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(
mode = “lines+markers”,
y = [4, 1, 3],
x = [“December”, “January”, “February”]))
fig.add_trace(go.Bar(x=[1,2,3], y=[2,3,4]))

fig.update_layout(
xaxis = dict(
tickangle = 90,
title_text = “Month”,
title_font = {“size”: 20},
title_standoff = 1),
yaxis = dict(
title_text = “Temperature”,
title_standoff = 25),
legend=dict(
#orientation=“h”,
itemsizing=“trace”,
font=dict(
family=“sans-serif”,
size=15,
color=“black”)))

fig.show()

Here is a tutorial about styling the legend : https://plot.ly/python/legend/#style-legend :slight_smile: