Plotly-express-19-plotly Specifies the size of a graph
This article describes how to set the size of a graph in Plotly in two ways
px
implementationgo.Figure
implementation

Px implementation
data
The data uses the built-in TIPS data set in PX
import plotly.express as px
df = px.data.tips()
df
Copy the code

drawing
fig = px.scatter(df, x="total_bill", y="tip", facet_col="sex",facet_row="smoker".# horizontal and vertical reference properties
width=1000, height=600)
fig.update_layout(
margin=dict(l=20, r=20, t=20, b=20), # Top, bottom, left, and right margins
paper_bgcolor="dodgerblue".# color
)
fig.show()
Copy the code

color
Recorded all the colors
liceblue, antiquewhite, aqua, aquamarine, azure,
beige, bisque, black, blanchedalmond, blue,
blueviolet, brown, burlywood, cadetblue,
chartreuse, chocolate, coral, cornflowerblue,
cornsilk, crimson, cyan, darkblue, darkcyan,
darkgoldenrod, darkgray, darkgrey, darkgreen,
darkkhaki, darkmagenta, darkolivegreen, darkorange,
darkorchid, darkred, darksalmon, darkseagreen,
darkslateblue, darkslategray, darkslategrey,
darkturquoise, darkviolet, deeppink, deepskyblue,
dimgray, dimgrey, dodgerblue, firebrick,
floralwhite, forestgreen, fuchsia, gainsboro,
ghostwhite, gold, goldenrod, gray, grey, green,
greenyellow, honeydew, hotpink, indianred, indigo,
ivory, khaki, lavender, lavenderblush, lawngreen,
lemonchiffon, lightblue, lightcoral, lightcyan,
lightgoldenrodyellow, lightgray, lightgrey,
lightgreen, lightpink, lightsalmon, lightseagreen,
lightskyblue, lightslategray, lightslategrey,
lightsteelblue, lightyellow, lime, limegreen,
linen, magenta, maroon, mediumaquamarine,
mediumblue, mediumorchid, mediumpurple,
mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue,
mintcream, mistyrose, moccasin, navajowhite, navy,
oldlace, olive, olivedrab, orange, orangered,
orchid, palegoldenrod, palegreen, paleturquoise,
palevioletred, papayawhip, peachpuff, peru, pink,
plum, powderblue, purple, red, rosybrown,
royalblue, rebeccapurple, saddlebrown, salmon,
sandybrown, seagreen, seashell, sienna, silver,
skyblue, slateblue, slategray, slategrey, snow,
springgreen, steelblue, tan, teal, thistle, tomato,
turquoise, violet, wheat, white, whitesmoke,
yellow, yellowgreen
Copy the code
. Go Figure
data
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[0.1.2.3.4.5.6.7.8].
y=[0.1.2.3.4.5.6.7.8]
))
fig.update_layout(
autosize=False.
width=800.
height=800.
margin=dict(
l=50.
r=50.
b=100.
t=100.
pad=9
),
paper_bgcolor="mediumaquamarine".
)
fig.show()
Copy the code

The second case
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(
x=["Apples"."Oranges"."Watermelon"."Pears"].
y=[3.2.1.4]
))
fig.update_layout(
autosize=False.
width=1000.
height=800.
yaxis=dict(
title_text="Y-axis Title".
ticktext=["Very long label"."long label"."3"."label"].
tickvals=[1.2.3.4].
tickmode="array".
titlefont=dict(size=50),
)
)
fig.update_yaxes(automargin=True) # Y-axis Title automatically moves to the appropriate position on the left
fig.show()
Copy the code

If set to False, the effect is:
