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

Skip to content

Fix axes vlines and hlines using wrong coordinates #25324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,14 +1101,25 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
# Extreme values of xmin/xmax/y. Using masked_verts here handles
# the case of y being a masked *object* array (as can be generated
# e.g. by errorbar()), which would make nanmin/nanmax stumble.
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])
updatex = True
updatey = True
if self.name == "rectilinear":
datalim = lines.get_datalim(self.transData)
t = lines.get_transform()
updatex, updatey = t.contains_branch_seperately(self.transData)
minx = np.nanmin(datalim.xmin)
maxx = np.nanmax(datalim.xmax)
miny = np.nanmin(datalim.ymin)
maxy = np.nanmax(datalim.ymax)
else:
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])

corners = (minx, miny), (maxx, maxy)
self.update_datalim(corners)
self.update_datalim(corners, updatex, updatey)
self._request_autoscale_view()

return lines

@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"],
Expand Down Expand Up @@ -1181,14 +1192,25 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
# Extreme values of x/ymin/ymax. Using masked_verts here handles
# the case of x being a masked *object* array (as can be generated
# e.g. by errorbar()), which would make nanmin/nanmax stumble.
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])
updatex = True
updatey = True
if self.name == "rectilinear":
datalim = lines.get_datalim(self.transData)
t = lines.get_transform()
updatex, updatey = t.contains_branch_seperately(self.transData)
minx = np.nanmin(datalim.xmin)
maxx = np.nanmax(datalim.xmax)
miny = np.nanmin(datalim.ymin)
maxy = np.nanmax(datalim.ymax)
else:
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])

corners = (minx, miny), (maxx, maxy)
self.update_datalim(corners)
self.update_datalim(corners, updatex, updatey)
self._request_autoscale_view()

return lines

@_preprocess_data(replace_names=["positions", "lineoffsets",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4920,6 +4920,20 @@ def test_lines_with_colors(fig_test, fig_ref, data):
colors=expect_color, linewidth=5)


@image_comparison(['vlines_hlines_blended_transform'],
extensions=['png'], style='mpl20')
def test_vlines_hlines_blended_transform():
t = np.arange(5.0, 10.0, 0.1)
s = np.exp(-t) + np.sin(2 * np.pi * t) + 10
fig, (hax, vax) = plt.subplots(2, 1, figsize=(6, 6))
hax.plot(t, s, '^')
hax.hlines([10, 9], xmin=0, xmax=0.5,
transform=hax.get_yaxis_transform(), colors='r')
vax.plot(t, s, '^')
vax.vlines([6, 7], ymin=0, ymax=0.15, transform=vax.get_xaxis_transform(),
colors='r')


@image_comparison(['step_linestyle', 'step_linestyle'], remove_text=True,
tol=0.2)
def test_step_linestyle():
Expand Down