@@ -2736,47 +2736,19 @@ def set_ymargin(self, m):
2736
2736
2737
2737
def margins (self , * margins , x = None , y = None , tight = True ):
2738
2738
"""
2739
- Set or retrieve autoscaling margins .
2739
+ Set or retrieve margins around the data for autoscaling axis limits .
2740
2740
2741
- The padding added to each limit of the Axes is the *margin*
2742
- times the data interval. All input parameters must be floats
2743
- greater than -0.5. Passing both positional and keyword
2744
- arguments is invalid and will raise a TypeError. If no
2745
- arguments (positional or otherwise) are provided, the current
2746
- margins will remain unchanged and simply be returned.
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))
2741
+ Autoscaling determines the axis limits by adding *margin* times the
2742
+ data interval as padding around the data. See the following illustration:
2762
2743
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")
2744
+ .. plot:: _embedded_plots/axes_margins.py
2769
2745
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")
2746
+ All input parameters must be floats greater than -0.5. Passing both
2747
+ positional and keyword arguments is invalid and will raise a TypeError.
2748
+ If no arguments (positional or otherwise) are provided, the current
2749
+ margins will remain unchanged and simply be returned.
2775
2750
2776
- Specifying any margin changes only the autoscaling; for example,
2777
- if *xmargin* is not None, then *xmargin* times the X data
2778
- interval will be added to each end of that interval before
2779
- it is used in autoscaling.
2751
+ The default margins are :rc:`axes.xmargin` and :rc:`axes.ymargin`.
2780
2752
2781
2753
Parameters
2782
2754
----------
@@ -2809,9 +2781,13 @@ def arrow(p1, p2, **props):
2809
2781
-----
2810
2782
If a previously used Axes method such as :meth:`pcolor` has set
2811
2783
:attr:`use_sticky_edges` to `True`, only the limits not set by
2812
- the "sticky artists" will be modified. To force all of the
2784
+ the "sticky artists" will be modified. To force all
2813
2785
margins to be set, set :attr:`use_sticky_edges` to `False`
2814
2786
before calling :meth:`margins`.
2787
+
2788
+ See Also
2789
+ --------
2790
+ set_xmargin, set_ymargin
2815
2791
"""
2816
2792
2817
2793
if margins and (x is not None or y is not None ):
0 commit comments