Skip to content

Commit 0747d5d

Browse files
DOC: Update two gallery examples with Figure.shift_origin as context manager (#3819)
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
1 parent fb718b2 commit 0747d5d

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

examples/gallery/3d_plots/scatter3d.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@
9292
zscale=1.5,
9393
)
9494

95-
# Shift plot origin in x direction
96-
fig.shift_origin(xshift="3.1c")
97-
# Add colorbar legend
98-
fig.colorbar()
95+
# Shift the plot origin in x direction temporarily and add the colorbar
96+
with fig.shift_origin(xshift=3.1):
97+
fig.colorbar()
9998

10099
fig.show()

examples/gallery/histograms/scatter_and_histograms.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,33 @@
4242
# level for all circles to deal with overplotting.
4343
fig.plot(x=x, y=y, style="c0.15c", fill=fill, transparency=50)
4444

45-
# Shift the plot origin and add top margin histogram.
46-
fig.shift_origin(yshift=height + 0.25)
45+
# Shift the plot origin in y direction temporarily and add top margin histogram.
46+
with fig.shift_origin(yshift=height + 0.25):
47+
fig.histogram(
48+
projection=f"X{width}/3",
49+
frame=["Wsrt", "xf", "yaf+lCounts"],
50+
# Give the same value for ymin and ymax to have them calculated automatically.
51+
region=[xmin, xmax, 0, 0],
52+
data=x,
53+
fill=fill,
54+
pen="0.1p,white",
55+
histtype=0,
56+
series=0.2,
57+
)
4758

48-
fig.histogram(
49-
projection=f"X{width}/3",
50-
frame=["Wsrt", "xf", "yaf+lCounts"],
51-
# Give the same value for ymin and ymax to have them calculated automatically.
52-
region=[xmin, xmax, 0, 0],
53-
data=x,
54-
fill=fill,
55-
pen="0.1p,white",
56-
histtype=0,
57-
series=0.2,
58-
)
59-
60-
# Shift the plot origin and add right margin histogram.
61-
fig.shift_origin(yshift=-height - 0.25, xshift=width + 0.25)
62-
63-
# Plot the horizontal histogram.
64-
fig.histogram(
65-
horizontal=True,
66-
projection=f"X3/{height}",
67-
# Note that the x- and y-axis are flipped, with the y-axis plotted horizontally.
68-
frame=["wSrt", "xf", "yaf+lCounts"],
69-
region=[ymin, ymax, 0, 0],
70-
data=y,
71-
fill=fill,
72-
pen="0.1p,white",
73-
histtype=0,
74-
series=0.2,
75-
)
59+
# Shift the plot origin in x direction temporarily and add right margin histogram.
60+
with fig.shift_origin(xshift=width + 0.25):
61+
# Plot the horizontal histogram.
62+
fig.histogram(
63+
horizontal=True,
64+
projection=f"X3/{height}",
65+
# Note that the x- and y-axes are flipped, with the y-axis plotted horizontally.
66+
frame=["wSrt", "xf", "yaf+lCounts"],
67+
region=[ymin, ymax, 0, 0],
68+
data=y,
69+
fill=fill,
70+
pen="0.1p,white",
71+
histtype=0,
72+
series=0.2,
73+
)
7674
fig.show()

0 commit comments

Comments
 (0)