Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -399,11 +399,20 @@ def test_matshow(self): | ||
fig, ax = plt.subplots() | ||
ax.matshow(...) | ||
@mpl.style.context("default") | ||
def test_pcolor(self): | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.sort(data, axis=0) | ||
fig, ax = plt.subplots() | ||
c = ax.pcolor(data, cmap='viridis') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. There is no use of dates in this call. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 call >>>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) 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
ax.set_title('Pseudocolor Plot with Datetime Data') | ||
ax.set_xticks(range(len(dates))) | ||
ax.set_xticklabels([d.strftime('%Y-%m-%d') for d in dates], rotation=45) | ||
fig.colorbar(c, ax=ax) | ||
fig.tight_layout() | ||
plt.close(fig) | ||
@pytest.mark.xfail(reason="Test for pcolorfast not written yet") | ||
@mpl.style.context("default") | ||