From f6e278430e437274025c133599439abefe8457c4 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 10 Mar 2017 12:01:13 +0000 Subject: [PATCH] Clean equal_aspect_ratio example Move equal_aspect_ratio example Fix broken faq link Add plot_ prefix --- doc/faq/howto_faq.rst | 3 ++- examples/pylab_examples/equal_aspect_ratio.py | 20 -------------- .../plot_equal_aspect_ratio.py | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 21 deletions(-) delete mode 100644 examples/pylab_examples/equal_aspect_ratio.py create mode 100644 examples/subplots_axes_and_figures/plot_equal_aspect_ratio.py diff --git a/doc/faq/howto_faq.rst b/doc/faq/howto_faq.rst index 5dd9f9fbc61f..d3014e672537 100644 --- a/doc/faq/howto_faq.rst +++ b/doc/faq/howto_faq.rst @@ -353,7 +353,8 @@ some ratio which controls the ratio:: .. htmlonly:: - See :ref:`pylab_examples-equal_aspect_ratio` for a complete example. + See :ref:`subplots_axes_and_figures-plot_equal_aspect_ratio` for a complete + example. .. _howto-twoscale: diff --git a/examples/pylab_examples/equal_aspect_ratio.py b/examples/pylab_examples/equal_aspect_ratio.py deleted file mode 100644 index 2461a0329b77..000000000000 --- a/examples/pylab_examples/equal_aspect_ratio.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Example: simple line plot. -Show how to make a plot that has equal 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) -plt.plot(t, s, '-', lw=2) - -plt.xlabel('time (s)') -plt.ylabel('voltage (mV)') -plt.title('About as simple as it gets, folks') -plt.grid(True) - -plt.gca().set_aspect('equal', 'datalim') - - -plt.show() diff --git a/examples/subplots_axes_and_figures/plot_equal_aspect_ratio.py b/examples/subplots_axes_and_figures/plot_equal_aspect_ratio.py new file mode 100644 index 000000000000..86ebd5bc83fd --- /dev/null +++ b/examples/subplots_axes_and_figures/plot_equal_aspect_ratio.py @@ -0,0 +1,26 @@ +""" +================= +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()