@@ -2745,6 +2745,34 @@ def margins(self, *margins, x=None, y=None, tight=True):
2745
2745
arguments (positional or otherwise) are provided, the current
2746
2746
margins will remain unchanged and simply be returned.
2747
2747
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
+
2748
2776
Specifying any margin changes only the autoscaling; for example,
2749
2777
if *xmargin* is not None, then *xmargin* times the X data
2750
2778
interval will be added to each end of that interval before
0 commit comments