diff --git a/doc/faq/howto_faq.rst b/doc/faq/howto_faq.rst index 7ac820021c4f..e2562eced83e 100644 --- a/doc/faq/howto_faq.rst +++ b/doc/faq/howto_faq.rst @@ -357,13 +357,10 @@ some ratio which controls the ratio:: ax = fig.add_subplot(111, aspect='equal') - - .. htmlonly:: - See :ref:`sphx_glr_gallery_subplots_axes_and_figures_equal_aspect_ratio.py` for a complete - example. - + See :ref:`sphx_glr_gallery_pylab_examples_axis_equal_demo.py` for a + complete example. .. _howto-twoscale: diff --git a/examples/pylab_examples/axis_equal_demo.py b/examples/pylab_examples/axis_equal_demo.py index 5a0298ef668d..4b5d928bc1fc 100644 --- a/examples/pylab_examples/axis_equal_demo.py +++ b/examples/pylab_examples/axis_equal_demo.py @@ -3,40 +3,32 @@ Axis Equal Demo =============== -This example is only interesting when run in interactive mode. - """ - import matplotlib.pyplot as plt import numpy as np -# Plot circle or radius 3 +# Plot circle of radius 3. an = np.linspace(0, 2*np.pi, 100) +fig, axs = plt.subplots(2, 2) + +axs[0, 0].plot(3*np.cos(an), 3*np.sin(an)) +axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10) + +axs[0, 1].plot(3*np.cos(an), 3*np.sin(an)) +axs[0, 1].axis('equal') +axs[0, 1].set_title('equal, looks like circle', fontsize=10) + +axs[1, 0].plot(3*np.cos(an), 3*np.sin(an)) +axs[1, 0].axis('equal') +axs[1, 0].axis([-3, 3, -3, 3]) +axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10) + +axs[1, 1].plot(3*np.cos(an), 3*np.sin(an)) +axs[1, 1].set_aspect('equal', 'box') +axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10) -plt.subplot(221) -plt.plot(3*np.cos(an), 3*np.sin(an)) -plt.title('not equal, looks like ellipse', fontsize=10) - -plt.subplot(222) -plt.plot(3*np.cos(an), 3*np.sin(an)) -plt.axis('equal') -plt.title('equal, looks like circle', fontsize=10) - -plt.subplot(223) -plt.plot(3*np.cos(an), 3*np.sin(an)) -plt.axis('equal') -plt.axis([-3, 3, -3, 3]) -plt.title('looks like circle, even after changing limits', fontsize=10) - -plt.subplot(224) -plt.plot(3*np.cos(an), 3*np.sin(an)) -plt.axis('equal') -plt.axis([-3, 3, -3, 3]) -plt.plot([0, 4], [0, 4]) -plt.title('still equal after adding line', fontsize=10) - -plt.tight_layout() +fig.tight_layout() plt.show() diff --git a/examples/pylab_examples/vline_hline_demo.py b/examples/pylab_examples/vline_hline_demo.py index dcb0fb733db9..458bb27327f9 100644 --- a/examples/pylab_examples/vline_hline_demo.py +++ b/examples/pylab_examples/vline_hline_demo.py @@ -7,26 +7,20 @@ """ import matplotlib.pyplot as plt -from matplotlib.transforms import blended_transform_factory as btf import numpy as np -def f(t): - s1 = np.sin(2 * np.pi * t) - e1 = np.exp(-t) - return np.abs(s1 * e1) + .05 - t = np.arange(0.0, 5.0, 0.1) -s = f(t) +s = np.exp(-t) + np.sin(2 * np.pi * t) + 1 nse = np.random.normal(0.0, 0.3, t.shape) * s -fig = plt.figure(figsize=(12, 6)) -vax = fig.add_subplot(121) -hax = fig.add_subplot(122) +fig, (vax, hax) = plt.subplots(1, 2, figsize=(12, 6)) vax.plot(t, s + nse, '^') vax.vlines(t, [0], s) -vax.vlines([1, 2], 0, 1, transform=btf(vax.transData, vax.transAxes), colors='r') +# By using ``transform=vax.get_xaxis_transform()`` the y coordinates are scaled +# such that 0 maps to the bottom of the axes and 1 to the top. +vax.vlines([1, 2], 0, 1, transform=vax.get_xaxis_transform(), colors='r') vax.set_xlabel('time (s)') vax.set_title('Vertical lines demo') diff --git a/examples/subplots_axes_and_figures/equal_aspect_ratio.py b/examples/subplots_axes_and_figures/equal_aspect_ratio.py deleted file mode 100644 index 86ebd5bc83fd..000000000000 --- a/examples/subplots_axes_and_figures/equal_aspect_ratio.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -================= -Equal aspect axes -================= - -This example shows how to make a plot whose x and y axes have a 1:1 aspect -ratio. -""" -import matplotlib.pyplot as plt -import numpy as np - -t = np.arange(0.0, 1.0 + 0.01, 0.01) -s = np.cos(2 * 2 * np.pi * t) - -fig, ax = plt.subplots() -ax.plot(t, s, '-', lw=2) - -ax.set_xlabel('Time (s)') -ax.set_ylabel('Voltage (mV)') -ax.set_title('About as simple as it gets, folks') -ax.grid(True) - -ax.set_aspect('equal', 'datalim') - -fig.tight_layout() -plt.show() diff --git a/examples/tests/backend_driver_sgskip.py b/examples/tests/backend_driver_sgskip.py index 909deb0a0eb1..ad4a91fff4c3 100644 --- a/examples/tests/backend_driver_sgskip.py +++ b/examples/tests/backend_driver_sgskip.py @@ -156,7 +156,6 @@ 'ellipse_collection.py', 'ellipse_demo.py', 'ellipse_rotated.py', - 'equal_aspect_ratio.py', 'errorbar_limits.py', 'fancyarrow_demo.py', 'fancybox_demo.py',