Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Added test_pcolor in test_datetime.py#27391

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
rawwash wants to merge4 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromrawwash:pcolor

Conversation

rawwash
Copy link
Contributor

@rawwashrawwash commentedNov 29, 2023
edited
Loading

PR summary

I have added a datetime smoke test for Axes.pcolor in lib/matplotlib/test/test_datetime.py.
This addresses the Axes.pcolor task from#26864.
pcolor test

PR checklist

Comment on lines 404 to 410
data = np.random.rand(10, 10)
fig, ax = plt.subplots()
ax.pcolor(...)
c = ax.pcolor(data)
fig.colorbar(c, ax=ax)
ax.set_title('Pseudocolor Plot Test')
assert c is not None, "Failed to create pcolor plot"
plt.close(fig)
Copy link
Member

Choose a reason for hiding this comment

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

This does not use datetime.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Since this is like a heat map, and we are only inputting integer data, do you think we should keep this test?

Copy link
Member

Choose a reason for hiding this comment

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

Unlike spy, youcan supply x and y values topcolor, and those are the ones that should be given datetimes here.

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.pcolor.html

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Changes complete!

QuLogic
QuLogic previously approved these changesNov 30, 2023
ax.pcolor(...)
base_date = datetime.date(2020, 1, 1)
dates = [base_date + datetime.timedelta(days=i) for i in range(10)]
data = np.random.rand(10, 10)
Copy link
Member

Choose a reason for hiding this comment

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

If you want to use randomness, you will need to set a seed (we use 19680801 for tests) or else the test image will change on each run.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sounds good, will add this seed to ensure the image does not change in each run.

data = np.random.rand(10, 10)
data = np.sort(data, axis=0)
fig, ax = plt.subplots()
c = ax.pcolor(data, cmap='viridis')
Copy link
Member

Choose a reason for hiding this comment

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

There is no use of dates in this call.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Both axes of pcolor require that I pass numerical data, how do you suggest I use dates? I can use datetime in this call, but then I would have to use date2num, which defies the purpose. Not sure how else to implement. This is what I found online:

'In my understanding, you would like to have date formatted tick labels for axes when using 'pcolor'. You cannot directly provide 'pcolor' with datetime vectors as of now.
However, there is a way to use the 'datenum ' and 'datetick ' functions to get datetime axes tick labels as illustrated in the example below:
%Creating two example vectors of datetimes, tx and ty
t1 = datetime(2017,9,2,0,0,0);
t2 = datetime(2017,9,30,0,0,0);
tx = t1:5:t2;
ty = tx + day(15);
%Creating an example C matrix for pcolor plot
C = magic(length(tx));
% Using datenum to convert to real numbers for plotting and dateticks for
% date labelling. You can play around with datetick options to suit your needs
pcolor(datenum(tx), datenum(ty), C);
datetick('y', 'dd-mm-yy', 'keepticks');
datetick('x', 'dd-mm-yy', 'keepticks');'

Copy link
Member

Choose a reason for hiding this comment

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

X and Y in fact,CAN take date info directly, no need to calldate2num...

>>>tx=ty=np.arange('2005-02','2005-03',dtype='datetime64[D]')>>>tx,ty=np.meshgrid(tx,ty)>>>c=np.arange(tx.size).reshape(tx.shape)>>>plt.pcolor(tx,ty,c)

yields
test

While I made no effort to clean up the labels so they were visible/not overlapping, the point stands that they are properly converted as desired/as is the point of these tests.

Copy link
Member

Choose a reason for hiding this comment

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

The answer you found is Matlab code about Matlab's plotting, which matplotlib was originally inspired by, but has diverged from significantly since then.

@QuLogicQuLogic dismissed theirstale reviewNovember 30, 2023 11:46

I don't think I intended to approve this yet.

@ksundenksunden mentioned this pull requestNov 30, 2023
64 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ksundenksundenksunden requested changes

@QuLogicQuLogicQuLogic left review comments

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@rawwash@QuLogic@ksunden@melissawm

[8]ページ先頭

©2009-2025 Movatter.jp