-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added test_hist2d #27418
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
base: main
Are you sure you want to change the base?
Added test_hist2d #27418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -355,12 +355,46 @@ def test_hist(self): | |||||
weights=values3 | ||||||
) | ||||||
|
||||||
@pytest.mark.xfail(reason="Test for hist2d not written yet") | ||||||
@mpl.style.context("default") | ||||||
def test_hist2d(self): | ||||||
fig, ax = plt.subplots() | ||||||
ax.hist2d(...) | ||||||
mpl.rcParams["date.converter"] = 'concise' | ||||||
|
||||||
start_date = datetime.datetime(2023, 10, 1) | ||||||
time_delta = datetime.timedelta(days=1) | ||||||
|
||||||
values1 = np.random.randint(1, 10, 30) | ||||||
values2 = np.random.randint(1, 10, 30) | ||||||
values3 = np.random.randint(1, 10, 30) | ||||||
|
||||||
x_values = mpl.dates.date2num([start_date + i * time_delta for i in range(30)]) | ||||||
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.
|
||||||
|
||||||
# Using Axes.hist2d | ||||||
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, constrained_layout=True) | ||||||
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.
Suggested change
|
||||||
|
||||||
# Testing with Axes.hist2d | ||||||
hist2d1 = ax1.hist2d( | ||||||
x_values, | ||||||
values1, | ||||||
bins=10, | ||||||
cmap='Blues' | ||||||
) | ||||||
Comment on lines
+375
to
+380
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. This fits in one line, AFAICT. |
||||||
ax1.set_title('Axes.hist2d - Data 1') | ||||||
|
||||||
hist2d2 = ax2.hist2d( | ||||||
x_values, | ||||||
values2, | ||||||
bins=10, | ||||||
cmap='Greens' | ||||||
) | ||||||
ax2.set_title('Axes.hist2d - Data 2') | ||||||
|
||||||
hist2d3 = ax3.hist2d( | ||||||
x_values, | ||||||
values3, | ||||||
bins=10, | ||||||
cmap='Reds' | ||||||
) | ||||||
ax3.set_title('Axes.hist2d - Data 3') | ||||||
Comment on lines
+383
to
+397
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. I don't see what the difference is between the first plot and these two? 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. To possibly clarify a bit: it would make more sense to use dates for the y-values as well. So one idea is to keep one of the subplots, swap x and y values for the next (dates on y-axis) and let the third have dates for both x and y-values. |
||||||
@mpl.style.context("default") | ||||||
def test_hlines(self): | ||||||
mpl.rcParams["date.converter"] = 'concise' | ||||||
|
There was a problem hiding this comment.
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'll need to set a seed (we use 19680801 for tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense