Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test_tripcolor (Issue #26864) plots with datetime on x-axis only , y-axis only, and both x- and y-axis #27491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bikegeek
Copy link

PR summary

Added code to test the tripcolor plotting with np.datetimes, based on the tripcolor(x,y,z) example in the Matplotlib user documentation. This is one of the numerous sub-tasks identified for testing various Axes.plottype ( where plottype= hist, scatter, violin, etc.) described in issue #26864

Generated plots look like the following:

Screenshot 2023-12-09 at 8 12 26 PM

PR checklist

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Can you do something like x_random_dates = np.datetime64('2020-01-01') + x.as_type('timedelata64[D]')? That way the underlying surface will not be randomized.

ax1.set(xlim=(min(x), max(x)), ylim=(min(y_rand_dates), max(y_rand_dates)))
ax2.set(xlim=(min(x_rand_dates), max(x_rand_dates)), ylim=(min(y_rand_dates),
max(y_rand_dates)))
fig.tight_layout()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fig.tight_layout()

mpl.rcParams["date.converter"] = 'concise'
plt.style.use('_mpl-gallery-nogrid')

fig, (ax, ax1, ax2) = plt.subplots(3, 1, figsize=(6, 4))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fig, (ax, ax1, ax2) = plt.subplots(3, 1, figsize=(6, 4))
fig, (ax, ax1, ax2) = plt.subplots(3, 1, figsize=(6, 4), layout='constrained')

fig, ax = plt.subplots()
ax.tripcolor(...)
mpl.rcParams["date.converter"] = 'concise'
plt.style.use('_mpl-gallery-nogrid')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
plt.style.use('_mpl-gallery-nogrid')

The gallery-style is not used for tests (and is already set by @mpl.style.context("default")).

@ksunden
Copy link
Member

ksunden commented Dec 12, 2023

I think that this is actually relatively recent that it works (thanks to probably #24522) but it does seem to work now, which is good. (I tested on a machine I hadn't pulled for a while on, and it didn't work, but after pulling it worked)

The second plot (ax1) looks odd, though... but I think that is just an aspect ratio/different scales on the axes problem, (the triangles are drawn essentially to maximize the minimum angle of the triangles, but that computation is done in x-y space, not in screen space so we are squishing some down so that they have smaller angles.) I don't think there is much to do here, as it is correct, but it did flag for me as odd.

@jklymak
Copy link
Member

jklymak commented Dec 12, 2023

Thats why I'd prefer the background data was retained, rather than be scrambled.

@ksunden
Copy link
Member

ksunden commented Dec 12, 2023

Further testing has shown that tripcolor does not actually behave as we wish it to, issue opened in #27499 to track it.

The axis units are not updated (and in fact I'm pretty sure if we used a different scale (other than D) the values would be off, it just happens to match mpl's internal model)

As such I'm inclined to not merge this for the time being (until the underlying problems are fixed)

Though perhaps remove the plot calls, since those hide the problem (by setting the axis units) so that this test is largely ready when the time comes. (along with some of the other edits)

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