Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b06302

Browse files
committed
fixes direction of arrowhead plot symbol for inverted x or y axes
1 parent 263b070 commit 1b06302

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,9 @@ def errorbar(self, x, y, yerr=None, xerr=None,
26022602
These arguments can be used to indicate that a value gives
26032603
only upper/lower limits. In that case a caret symbol is
26042604
used to indicate this. lims-arguments may be of the same
2605-
type as *xerr* and *yerr*.
2605+
type as *xerr* and *yerr*. To use limits with inverted
2606+
axes, :meth:`set_xlim` or :meth:`set_ylim` must be called
2607+
before :meth:`errorbar`.
26062608
26072609
*errorevery*: positive integer
26082610
subsamples the errorbars. e.g., if everyerror=5, errorbars for
@@ -2754,7 +2756,7 @@ def xywhere(xs, ys, mask):
27542756
right = [thisx + thiserr for (thisx, thiserr)
27552757
in cbook.safezip(x, xerr)]
27562758

2757-
# select points without upper/lower limits in x
2759+
# select points without upper/lower limits in x and
27582760
# draw normal errorbars for these points
27592761
noxlims = ~(xlolims | xuplims)
27602762
if noxlims.any():
@@ -2770,9 +2772,13 @@ def xywhere(xs, ys, mask):
27702772
lo, ro = xywhere(x, right, xlolims & everymask)
27712773
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
27722774
rightup, yup = xywhere(right, y, xlolims & everymask)
2775+
if self.xaxis_inverted():
2776+
marker = mlines.CARETLEFT
2777+
else:
2778+
marker = mlines.CARETRIGHT
27732779
caplines.extend(
2774-
self.plot(rightup, yup, ls='None',
2775-
marker=mlines.CARETRIGHT, **plot_kw))
2780+
self.plot(rightup, yup, ls='None', marker=marker,
2781+
**plot_kw))
27762782
if capsize > 0:
27772783
xlo, ylo = xywhere(x, y, xlolims & everymask)
27782784
caplines.extend(self.plot(xlo, ylo, 'k|', **plot_kw))
@@ -2782,9 +2788,13 @@ def xywhere(xs, ys, mask):
27822788
lo, ro = xywhere(left, x, xuplims & everymask)
27832789
barcols.append(self.hlines(yo, lo, ro, **lines_kw))
27842790
leftlo, ylo = xywhere(left, y, xuplims & everymask)
2791+
if self.xaxis_inverted():
2792+
marker = mlines.CARETRIGHT
2793+
else:
2794+
marker = mlines.CARETLEFT
27852795
caplines.extend(
2786-
self.plot(leftlo, ylo, ls='None',
2787-
marker=mlines.CARETLEFT, **plot_kw))
2796+
self.plot(leftlo, ylo, ls='None', marker=marker,
2797+
**plot_kw))
27882798
if capsize > 0:
27892799
xup, yup = xywhere(x, y, xuplims & everymask)
27902800
caplines.extend(self.plot(xup, yup, 'k|', **plot_kw))
@@ -2804,7 +2814,7 @@ def xywhere(xs, ys, mask):
28042814
upper = [thisy + thiserr for (thisy, thiserr)
28052815
in cbook.safezip(y, yerr)]
28062816

2807-
# select points without upper/lower limits in y
2817+
# select points without upper/lower limits in y and
28082818
# draw normal errorbars for these points
28092819
noylims = ~(lolims | uplims)
28102820
if noylims.any():
@@ -2820,9 +2830,13 @@ def xywhere(xs, ys, mask):
28202830
lo, uo = xywhere(y, upper, lolims & everymask)
28212831
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
28222832
xup, upperup = xywhere(x, upper, lolims & everymask)
2833+
if self.yaxis_inverted():
2834+
marker = mlines.CARETDOWN
2835+
else:
2836+
marker = mlines.CARETUP
28232837
caplines.extend(
2824-
self.plot(xup, upperup, ls='None',
2825-
marker=mlines.CARETUP, **plot_kw))
2838+
self.plot(xup, upperup, ls='None', marker=marker,
2839+
**plot_kw))
28262840
if capsize > 0:
28272841
xlo, ylo = xywhere(x, y, lolims & everymask)
28282842
caplines.extend(self.plot(xlo, ylo, 'k_', **plot_kw))
@@ -2832,9 +2846,13 @@ def xywhere(xs, ys, mask):
28322846
lo, uo = xywhere(lower, y, uplims & everymask)
28332847
barcols.append(self.vlines(xo, lo, uo, **lines_kw))
28342848
xlo, lowerlo = xywhere(x, lower, uplims & everymask)
2849+
if self.yaxis_inverted():
2850+
marker = mlines.CARETUP
2851+
else:
2852+
marker = mlines.CARETDOWN
28352853
caplines.extend(
2836-
self.plot(xlo, lowerlo, ls='None',
2837-
marker=mlines.CARETDOWN, **plot_kw))
2854+
self.plot(xlo, lowerlo, ls='None', marker=marker,
2855+
**plot_kw))
28382856
if capsize > 0:
28392857
xup, yup = xywhere(x, y, uplims & everymask)
28402858
caplines.extend(self.plot(xup, yup, 'k_', **plot_kw))

0 commit comments

Comments
 (0)