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

Skip to content

Commit 930c35b

Browse files
committed
RR - fix axes vlines and hlines using wrong coordinates
1 parent 70e0ba8 commit 930c35b

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,18 +1173,30 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
11731173

11741174
lines = mcoll.LineCollection(masked_verts, colors=colors,
11751175
linestyles=linestyles, label=label)
1176+
if 'transform' in kwargs:
1177+
lines.set_transform(kwargs['transform'])
11761178
self.add_collection(lines, autolim=False)
1179+
self._unstale_viewLim()
11771180
lines._internal_update(kwargs)
11781181

11791182
if len(x) > 0:
11801183
# Extreme values of x/ymin/ymax. Using masked_verts here handles
11811184
# the case of x being a masked *object* array (as can be generated
11821185
# e.g. by errorbar()), which would make nanmin/nanmax stumble.
1183-
minx = np.nanmin(masked_verts[..., 0])
1184-
maxx = np.nanmax(masked_verts[..., 0])
1185-
miny = np.nanmin(masked_verts[..., 1])
1186-
maxy = np.nanmax(masked_verts[..., 1])
1187-
corners = (minx, miny), (maxx, maxy)
1186+
if self.name == "rectilinear":
1187+
datalim = lines.get_datalim(self.transData)
1188+
minx = np.nanmin(datalim.xmin)
1189+
maxx = np.nanmax(datalim.xmax)
1190+
miny = np.nanmin(datalim.ymin)
1191+
maxy = np.nanmax(datalim.ymax)
1192+
corners = (minx, miny), (maxx, maxy)
1193+
else:
1194+
minx = np.nanmin(masked_verts[..., 0])
1195+
maxx = np.nanmax(masked_verts[..., 0])
1196+
miny = np.nanmin(masked_verts[..., 1])
1197+
maxy = np.nanmax(masked_verts[..., 1])
1198+
corners = (minx, miny), (maxx, maxy)
1199+
11881200
self.update_datalim(corners)
11891201
self._request_autoscale_view()
11901202

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,6 +4938,17 @@ def test_lines_with_colors(fig_test, fig_ref, data):
49384938
colors=expect_color, linewidth=5)
49394939

49404940

4941+
@image_comparison(['vlines_blended_transform'],
4942+
extensions=['png'], style='mpl20')
4943+
def test_vlines_blended_transform():
4944+
t = np.arange(5.0, 10.0, 0.1)
4945+
s = np.exp(-t) + np.sin(2 * np.pi * t) + 10
4946+
vax = plt.figure(figsize=(12, 6)).gca()
4947+
vax.plot(t, s, '^')
4948+
vax.vlines([6, 7], ymin=0, ymax=0.15, transform=vax.get_xaxis_transform(),
4949+
colors='r')
4950+
4951+
49414952
@image_comparison(['step_linestyle', 'step_linestyle'], remove_text=True)
49424953
def test_step_linestyle():
49434954
x = y = np.arange(10)

0 commit comments

Comments
 (0)