Skip to content

Commit ee5ccc7

Browse files
committed
Edited documentation, modified square plot test
1 parent 53a2d2c commit ee5ccc7

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

doc/users/whats_new/square_plot_feature.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ Square Plot
33

44
Square plot:
55

6-
Added implementation of square plot feature that sets the axes of a plot
7-
to have the same maximum difference between them, and set the scale to be
8-
the same for both axes, creating a square plot.
6+
Implemented square plots feature as a new parameter in the axis function. When argument 'square' is specified, equal scaling is set, and the limits are set such that xmax-xmin == ymax-ymin.
97

10-
Example shown by:
8+
Example:
119

1210
``ax.axis('square')``
1311

lib/matplotlib/axes/_base.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,13 +1287,44 @@ def apply_aspect(self, position=None):
12871287

12881288
def axis(self, *v, **kwargs):
12891289
"""
1290-
Convenience method for manipulating the x and y view limits
1291-
and the aspect ratio of the plot. For details, see
1292-
:func:`~matplotlib.pyplot.axis`.
1290+
Call signature::
1291+
1292+
axis(*v, **kwargs)
1293+
1294+
Examples:
1295+
1296+
axis('equal')
1297+
axis([0, 10, 2, 8])
1298+
axis(xmin=1, xmax=2)
1299+
1300+
Convenience method for manipulating axis properties such as
1301+
the x and y view limits and the aspect ratio of the plot.
1302+
1303+
ACCEPTS: [length 4 sequence of floats
1304+
| 'on' | 'off' | 'equal' | 'tight' | 'scaled'
1305+
| 'normal' | 'auto' | 'image'| 'square' ]
1306+
1307+
Keyword arguments:
1308+
1309+
*xmin*:scalar
1310+
Minimum limit on the x-axis
1311+
1312+
*xmax*:scalar
1313+
Maximum limit on the x-axis
1314+
1315+
*ymin*:scalar
1316+
Minimum limit on the y-axis
1317+
1318+
*ymax*:scalar
1319+
Maximum limit on the y-axis
12931320
12941321
*kwargs* are passed on to :meth:`set_xlim` and
12951322
:meth:`set_ylim`
1323+
1324+
For details, see
1325+
:func:`~matplotlib.pyplot.axis`.
12961326
"""
1327+
12971328
if len(v) == 0 and len(kwargs) == 0:
12981329
xmin, xmax = self.get_xlim()
12991330
ymin, ymax = self.get_ylim()

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,9 +1410,9 @@ def axis(*v, **kwargs):
14101410
14111411
>>> axis('square')
14121412
1413-
changes the limits of the (*xmax*-*xmin*) and (*ymax*-*ymin*) of
1413+
changes the limit ranges (*xmax*-*xmin*) and (*ymax*-*ymin*) of
14141414
the *x* and *y* axes to be the same, and have the same scaling,
1415-
resulting in a square plot
1415+
resulting in a square plot.
14161416
14171417
.. seealso::
14181418
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3635,13 +3635,16 @@ def test_bar_negative_width():
36353635
assert_equal(b._width, 1)
36363636
assert_equal(b._height, indx + 1)
36373637

3638-
@image_comparison(baseline_images=['square_plot'], extensions=['png'])
3638+
@cleanup
36393639
def test_square_plot():
36403640
x = np.arange(4)
36413641
y = np.array([1., 3., 5., 7.])
36423642
fig, ax = plt.subplots()
36433643
ax.plot(x, y, 'mo')
36443644
ax.axis('square')
3645+
xlim, ylim = ax.get_xlim(), ax.get_ylim()
3646+
assert_true(np.diff(xlim) == np.diff(ylim))
3647+
assert_true(ax.get_aspect() == 'equal')
36453648

36463649
if __name__ == '__main__':
36473650
import nose

0 commit comments

Comments
 (0)