Skip to content

DOC: Update two gallery examples with Figure.shift_origin as context manager #3819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/gallery/3d_plots/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@
zscale=1.5,
)

# Shift plot origin in x direction
fig.shift_origin(xshift="3.1c")
# Add colorbar legend
fig.colorbar()
# Shift the plot origin in x direction temporarily and add the colorbar
with fig.shift_origin(xshift=3.1):
fig.colorbar()

fig.show()
58 changes: 28 additions & 30 deletions examples/gallery/histograms/scatter_and_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,33 @@
# level for all circles to deal with overplotting.
fig.plot(x=x, y=y, style="c0.15c", fill=fill, transparency=50)

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

fig.histogram(
projection=f"X{width}/3",
frame=["Wsrt", "xf", "yaf+lCounts"],
# Give the same value for ymin and ymax to have them calculated automatically.
region=[xmin, xmax, 0, 0],
data=x,
fill=fill,
pen="0.1p,white",
histtype=0,
series=0.2,
)

# Shift the plot origin and add right margin histogram.
fig.shift_origin(yshift=-height - 0.25, xshift=width + 0.25)

# Plot the horizontal histogram.
fig.histogram(
horizontal=True,
projection=f"X3/{height}",
# Note that the x- and y-axis are flipped, with the y-axis plotted horizontally.
frame=["wSrt", "xf", "yaf+lCounts"],
region=[ymin, ymax, 0, 0],
data=y,
fill=fill,
pen="0.1p,white",
histtype=0,
series=0.2,
)
# Shift the plot origin in x direction temporarily and add right margin histogram.
with fig.shift_origin(xshift=width + 0.25):
# Plot the horizontal histogram.
fig.histogram(
horizontal=True,
projection=f"X3/{height}",
# Note that the x- and y-axes are flipped, with the y-axis plotted horizontally.
frame=["wSrt", "xf", "yaf+lCounts"],
region=[ymin, ymax, 0, 0],
data=y,
fill=fill,
pen="0.1p,white",
histtype=0,
series=0.2,
)
fig.show()