Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac10acb

Browse filesBrowse files
committed
Cleanup imshow_extent tutorial.
- Move title-setting out to make it hopefully clearer (it's the first row that matters, not the one with `extent=None`). - Define the kwargs to annotate() at a single call site rather than in a separate dict. - Add show() to make the example runnable from the command-line.
1 parent 17ef13b commit ac10acb
Copy full SHA for ac10acb

File tree

Expand file treeCollapse file tree

1 file changed

+7
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-11
lines changed
Open diff view settings
Collapse file

‎tutorials/intermediate/imshow_extent.py‎

Copy file name to clipboardExpand all lines: tutorials/intermediate/imshow_extent.py
+7-11Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,15 @@ def generate_imshow_demo_grid(extents, xlim=None, ylim=None):
148148
for ax, extent in zip(columns[origin], extents):
149149
plot_imshow_with_labels(ax, data, extent, origin, xlim, ylim)
150150

151+
columns['label'][0].set_title('extent=')
151152
for ax, extent in zip(columns['label'], extents):
152-
text_kwargs = {'ha': 'right',
153-
'va': 'center',
154-
'xycoords': 'axes fraction',
155-
'xy': (1, .5)}
156153
if extent is None:
157-
ax.annotate('None', **text_kwargs)
158-
ax.set_title('extent=')
154+
text = 'None'
159155
else:
160156
left, right, bottom, top = extent
161-
text = ('left: {left:0.1f}\nright: {right:0.1f}\n' +
162-
'bottom: {bottom:0.1f}\ntop: {top:0.1f}\n').format(
163-
left=left, right=right, bottom=bottom, top=top)
164-
165-
ax.annotate(text, **text_kwargs)
157+
text = (f'left: {left:0.1f}\nright: {right:0.1f}\n'
158+
f'bottom: {bottom:0.1f}\ntop: {top:0.1f}\n')
159+
ax.text(1., .5, text, transform=ax.transAxes, ha='right', va='center')
166160
ax.axis('off')
167161
return columns
168162

@@ -263,3 +257,5 @@ def generate_imshow_demo_grid(extents, xlim=None, ylim=None):
263257

264258
generate_imshow_demo_grid(extents=[None] + extents,
265259
xlim=(-2, 8), ylim=(-1, 6))
260+
261+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.