Skip to content

DOC: Fix example for what's new imshow so it isn't cut off or crowded. - #24441

Merged
timhoffm merged 7 commits into
matplotlib:mainfrom
stefmolin:imshow-extent-cutoff-whatsnew
Nov 14, 2022
Merged

DOC: Fix example for what's new imshow so it isn't cut off or crowded.#24441
timhoffm merged 7 commits into
matplotlib:mainfrom
stefmolin:imshow-extent-cutoff-whatsnew

Conversation

@stefmolin

@stefmolin stefmolin commented Nov 12, 2022

Copy link
Copy Markdown
Contributor

PR Summary

The example for the What's new entry on the extent parameter to imshow currently has a very crowded y-axis and the labels are being cut off:
Screen Shot 2022-11-12 at 1 45 55 PM

I reduced the number of major ticks and adjusted the figure size in addition to calling tight_layout() to fix this. It now looks like the below in the built docs.
Screen Shot 2022-11-12 at 2 21 16 PM

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • [N/A] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@stefmolin
stefmolin marked this pull request as ready for review November 12, 2022 19:22
@jklymak

jklymak commented Nov 12, 2022

Copy link
Copy Markdown
Member

Suggest constrained layout and concise date formatter.

@stefmolin

Copy link
Copy Markdown
Contributor Author

By "concise date formatter", did you mean something like this? TBH this seems confusing...
Screen Shot 2022-11-12 at 4 29 03 PM

@jklymak

jklymak commented Nov 12, 2022

Copy link
Copy Markdown
Member

I prefer the concise locator version, but I'm biased...

@stefmolin

stefmolin commented Nov 12, 2022

Copy link
Copy Markdown
Contributor Author

What about something like this?
Screen Shot 2022-11-12 at 5 51 54 PM

@jklymak

jklymak commented Nov 13, 2022

Copy link
Copy Markdown
Member

I'm not going to block on that, but I don't find having 00:00 next to the day all that useful.

@stefmolin

Copy link
Copy Markdown
Contributor Author

Since this example has so many ticks so close together, I think this helps avoid confusion of the ticks being multiline entries e.g., Jan-10\n12:00 kind of looks like a single label because the axis is so dense, but it is actually two labels Jan-10 00:00 and Jan-10 12:00. If anything, there is now a bonus of providing some ways to tweak the output of ConciseDateFormatter.

@stefmolin

stefmolin commented Nov 13, 2022

Copy link
Copy Markdown
Contributor Author

Here's the updated page in the docs. This is also 3.7 #22230

@dstansby dstansby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks 👍 - just two non-blocking suggestions. I think that having 00:00 next to the date is better than having just the date.

Comment thread doc/users/next_whats_new/imshow_extent_units.rst Outdated
Comment thread doc/users/next_whats_new/imshow_extent_units.rst Outdated

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is about extents and not about date formatting, I propose to simplify the y ticks further:

  • reduce to only one major tick per day (more ticks don't make sense because you have only one image pixel per day)
  • thus, also don't activate minor ticks
  • set the date format to "%d/%m%y" (no hours)

@jklymak

jklymak commented Nov 13, 2022

Copy link
Copy Markdown
Member

If you simply do:

import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['date.converter'] = 'concise'

fig, ax = plt.subplots(layout='constrained')
date_first = np.datetime64('2020-01-01', 'D')
date_last = np.datetime64('2020-01-11', 'D')
arr = [[i+j for i in range(10)] for j in range(10)]

ax.imshow(arr, origin='lower', extent=[1, 11, date_first, date_last])

Without any monkeying with ticks or formatters, you get the pretty straight forward:
Figure_1

@timhoffm

timhoffm commented Nov 13, 2022

Copy link
Copy Markdown
Member

I would even leave out plt.rcParams['date.converter'] = 'concise'. IMHO this is not making it better here. Having only the numbers 02..11 on the y-axis (and a bit weird 'Jan') makes it less clear that the extent has been set to dates. So better without it:

image

Optional: I also switched the x-extent from [1, 11], to [0, 10] because it looks slightly better to have ticks on the boundaries. But that's just a minor stylistic thing.

@stefmolin

Copy link
Copy Markdown
Contributor Author

I agree with @timhoffm – I will update the example.

@timhoffm timhoffm added this to the v3.7.0 milestone Nov 14, 2022
@timhoffm
timhoffm merged commit 1fa7467 into matplotlib:main Nov 14, 2022
@stefmolin
stefmolin deleted the imshow-extent-cutoff-whatsnew branch November 15, 2022 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants