Skip to content

Commit 7cfeea0

Browse files
committed
Make heatmaps square by default
1 parent 275de77 commit 7cfeea0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

proplot/axes/base.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,20 +1297,37 @@ def get_tightbbox(self, renderer, *args, **kwargs):
12971297
self._tightbbox = bbox
12981298
return bbox
12991299

1300-
def heatmap(self, *args, **kwargs):
1300+
def heatmap(self, *args, aspect=None, **kwargs):
13011301
"""
13021302
Pass all arguments to `~matplotlib.axes.Axes.pcolormesh` then apply
13031303
settings that are suitable for heatmaps: no gridlines, no minor ticks,
13041304
and major ticks at the center of each grid box.
1305+
1306+
Parameters
1307+
----------
1308+
aspect : {'equal', 'auto'} or float, optional
1309+
Controls the aspect ratio of the axes. The aspect is of particular
1310+
relevance for heatmaps since it may distort the heatmap, i.e. a grid box
1311+
will not be square. This parameter is a shortcut for explicitly calling
1312+
`~matplotlib.axes.set_aspect`.
1313+
1314+
The default is :rc:`image.heatmap`. The options are:
1315+
1316+
- ``'equal'``: Ensures an aspect ratio of 1. Grid boxes will be square.
1317+
- ``'auto'``: The axes is kept fixed and the aspect is adjusted so
1318+
that the data fit in the axes. In general, this will result in non-square
1319+
grid boxes.
13051320
"""
13061321
obj = self.pcolormesh(*args, **kwargs)
1322+
aspect = _not_none(aspect, rc['image.aspect'])
13071323
xlocator, ylocator = None, None
13081324
if hasattr(obj, '_coordinates'):
13091325
coords = obj._coordinates
13101326
coords = (coords[1:, ...] + coords[:-1, ...]) / 2
13111327
coords = (coords[:, 1:, :] + coords[:, :-1, :]) / 2
13121328
xlocator, ylocator = coords[0, :, 0], coords[:, 0, 1]
13131329
self.format(
1330+
aspect=aspect,
13141331
xgrid=False, ygrid=False, xtickminor=False, ytickminor=False,
13151332
xlocator=xlocator, ylocator=ylocator,
13161333
)

0 commit comments

Comments
 (0)