Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36af98e

Browse filesBrowse files
committed
DOC: Add a plot to margins() to visualize the effect
1 parent 5a0cdf1 commit 36af98e
Copy full SHA for 36af98e

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,34 @@ def margins(self, *margins, x=None, y=None, tight=True):
27452745
arguments (positional or otherwise) are provided, the current
27462746
margins will remain unchanged and simply be returned.
27472747
2748+
.. plot::
2749+
2750+
import numpy as np
2751+
import matplotlib.pyplot as plt
2752+
2753+
x, y = np.meshgrid(np.linspace(0, 1, 10), np.linspace(0, 1, 10))
2754+
fig, ax = plt.subplots()
2755+
ax.plot(x, y, 'o', color='lightblue')
2756+
ax.margins(1.5, 0.5)
2757+
ax.set_title("margins(x=1.5, y=0.5)")
2758+
2759+
def arrow(p1, p2, **props):
2760+
ax.annotate("", p1, p2,
2761+
arrowprops=dict(arrowstyle="<->", shrinkA=0, shrinkB=0, **props))
2762+
2763+
arrow((-1.5, 0), (0, 0), color="orange")
2764+
arrow((0, 0), (1, 0), color="sienna")
2765+
arrow((1, 0), (2.5, 0), color="orange")
2766+
ax.text(-0.75, -0.1, "x margin * x data range", ha="center",
2767+
color="orange")
2768+
ax.text(0.5, -0.1, "x data range", ha="center", color="sienna")
2769+
2770+
arrow((1, -0.5), (1, 0), color="tab:green")
2771+
arrow((1, 0), (1, 1), color="darkgreen")
2772+
arrow((1, 1), (1, 1.5), color="tab:green")
2773+
ax.text(1.1, 1.25, "y margin * y data range", color="tab:green")
2774+
ax.text(1.1, 0.5, "y data range", color="darkgreen")
2775+
27482776
Specifying any margin changes only the autoscaling; for example,
27492777
if *xmargin* is not None, then *xmargin* times the X data
27502778
interval will be added to each end of that interval before

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.