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

Skip to content

Commit 29e4ea1

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

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
11131113
@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"],
11141114
label_namer="x")
11151115
def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
1116-
label='', **kwargs):
1116+
label='', transform=None, **kwargs):
11171117
"""
11181118
Plot vertical lines at each *x* from *ymin* to *ymax*.
11191119
@@ -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 is not None:
1177+
lines.set_transform(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 == "polar":
1187+
minx = np.nanmin(masked_verts[..., 0])
1188+
maxx = np.nanmax(masked_verts[..., 0])
1189+
miny = np.nanmin(masked_verts[..., 1])
1190+
maxy = np.nanmax(masked_verts[..., 1])
1191+
corners = (minx, miny), (maxx, maxy)
1192+
else:
1193+
datalim = lines.get_datalim(self.transData)
1194+
minx = np.nanmin(datalim.xmin)
1195+
maxx = np.nanmax(datalim.xmax)
1196+
miny = np.nanmin(datalim.ymin)
1197+
maxy = np.nanmax(datalim.ymax)
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)