Add an infinitely long straight line. The line can be defined either by two points *xy1* and *xy2*, or by one point *xy1* and a *slope*. This draws a straight line "on the screen", regardless of the x and y scales, and is thus also suitable for drawing expo
(self, xy1, xy2=None, *, slope=None, **kwargs)
| 920 | |
| 921 | @_docstring.interpd |
| 922 | def axline(self, xy1, xy2=None, *, slope=None, **kwargs): |
| 923 | """ |
| 924 | Add an infinitely long straight line. |
| 925 | |
| 926 | The line can be defined either by two points *xy1* and *xy2*, or |
| 927 | by one point *xy1* and a *slope*. |
| 928 | |
| 929 | This draws a straight line "on the screen", regardless of the x and y |
| 930 | scales, and is thus also suitable for drawing exponential decays in |
| 931 | semilog plots, power laws in loglog plots, etc. However, *slope* |
| 932 | should only be used with linear scales; It has no clear meaning for |
| 933 | all other scales, and thus the behavior is undefined. Please specify |
| 934 | the line using the points *xy1*, *xy2* for non-linear scales. |
| 935 | |
| 936 | The *transform* keyword argument only applies to the points *xy1*, |
| 937 | *xy2*. The *slope* (if given) is always in data coordinates. This can |
| 938 | be used e.g. with ``ax.transAxes`` for drawing grid lines with a fixed |
| 939 | slope. |
| 940 | |
| 941 | Parameters |
| 942 | ---------- |
| 943 | xy1, xy2 : (float, float) |
| 944 | Points for the line to pass through. |
| 945 | Either *xy2* or *slope* has to be given. |
| 946 | slope : float, optional |
| 947 | The slope of the line. Either *xy2* or *slope* has to be given. |
| 948 | |
| 949 | Returns |
| 950 | ------- |
| 951 | `.AxLine` |
| 952 | |
| 953 | Other Parameters |
| 954 | ---------------- |
| 955 | **kwargs |
| 956 | Valid kwargs are `.Line2D` properties |
| 957 | |
| 958 | %(Line2D:kwdoc)s |
| 959 | |
| 960 | See Also |
| 961 | -------- |
| 962 | axhline : for horizontal lines |
| 963 | axvline : for vertical lines |
| 964 | |
| 965 | Examples |
| 966 | -------- |
| 967 | Draw a thick red line passing through (0, 0) and (1, 1):: |
| 968 | |
| 969 | >>> axline((0, 0), (1, 1), linewidth=4, color='r') |
| 970 | """ |
| 971 | if slope is not None and (self.get_xscale() != 'linear' or |
| 972 | self.get_yscale() != 'linear'): |
| 973 | raise TypeError("'slope' cannot be used with non-linear scales") |
| 974 | |
| 975 | datalim = [xy1] if xy2 is None else [xy1, xy2] |
| 976 | if "transform" in kwargs: |
| 977 | # if a transform is passed (i.e. line points not in data space), |
| 978 | # data limits should not be adjusted. |
| 979 | datalim = [] |