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

Skip to content

Commit 4a1af9c

Browse files
Fix errorbar autoscaling inconsistency on log axes (#31478)
* Fix errorbar autoscaling inconsistency on log axes (fixes #31462) * Move log scale fix from _axes.py to collections.py root cause * Use single figure for log autoscale test * Fix formatting issues
1 parent c0c18c9 commit 4a1af9c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/matplotlib/collections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ def get_datalim(self, transData):
291291
if isinstance(offsets, np.ma.MaskedArray):
292292
offsets = offsets.filled(np.nan)
293293
# get_path_collection_extents handles nan but not masked arrays
294+
data_trf = transform.get_affine() - transData
295+
if not data_trf.is_affine:
296+
paths = [data_trf.transform_path_non_affine(p) for p in paths]
294297
return mpath.get_path_collection_extents(
295-
transform.get_affine() - transData, paths,
298+
data_trf.get_affine(), paths,
296299
self.get_transforms(),
297300
offset_trf.transform_non_affine(offsets),
298301
offset_trf.get_affine().frozen())

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,6 +4690,25 @@ def test_errorbar_limits():
46904690
ax.set_title('Errorbar upper and lower limits')
46914691

46924692

4693+
def test_errorbar_log_autoscale_order_independent():
4694+
x = 10 ** np.array([18, 18.1, 18.2, 18.3])
4695+
y = np.array([100, 80, 60, 30])
4696+
yerr = np.ones_like(y) * 10
4697+
4698+
fig, (ax1, ax2) = plt.subplots(2)
4699+
4700+
ax1.set_xscale("log")
4701+
ax1.set_yscale("log")
4702+
ax1.errorbar(x, y, yerr=yerr)
4703+
4704+
ax2.errorbar(x, y, yerr=yerr)
4705+
ax2.set_xscale("log")
4706+
ax2.set_yscale("log")
4707+
4708+
assert_allclose(ax1.get_xlim(), ax2.get_xlim())
4709+
assert_allclose(ax1.get_ylim(), ax2.get_ylim())
4710+
4711+
46934712
def test_errorbar_nonefmt():
46944713
# Check that passing 'none' as a format still plots errorbars
46954714
x = np.arange(5)

0 commit comments

Comments
 (0)