Skip to content

Commit 7c02e85

Browse files
Added test_hist in test_datetime.py (#27028)
* Added test_hist * reset * remove comment * Added test_hist * added test_hist.py to test_datetime.py * comply with PEP8 * datetime as bins * datetime as bins
1 parent c06a97e commit 7c02e85

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

lib/matplotlib/tests/test_datetime.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,52 @@ def test_hexbin(self):
170170
fig, ax = plt.subplots()
171171
ax.hexbin(...)
172172

173-
@pytest.mark.xfail(reason="Test for hist not written yet")
174173
@mpl.style.context("default")
175174
def test_hist(self):
176-
fig, ax = plt.subplots()
177-
ax.hist(...)
175+
mpl.rcParams["date.converter"] = 'concise'
176+
177+
start_date = datetime.datetime(2023, 10, 1)
178+
time_delta = datetime.timedelta(days=1)
179+
180+
values1 = np.random.randint(1, 10, 30)
181+
values2 = np.random.randint(1, 10, 30)
182+
values3 = np.random.randint(1, 10, 30)
183+
184+
bin_edges = [start_date + i * time_delta for i in range(31)]
185+
186+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True)
187+
ax1.hist(
188+
[start_date + i * time_delta for i in range(30)],
189+
bins=10,
190+
weights=values1
191+
)
192+
ax2.hist(
193+
[start_date + i * time_delta for i in range(30)],
194+
bins=10,
195+
weights=values2
196+
)
197+
ax3.hist(
198+
[start_date + i * time_delta for i in range(30)],
199+
bins=10,
200+
weights=values3
201+
)
202+
203+
fig, (ax4, ax5, ax6) = plt.subplots(3, 1, constrained_layout=True)
204+
ax4.hist(
205+
[start_date + i * time_delta for i in range(30)],
206+
bins=bin_edges,
207+
weights=values1
208+
)
209+
ax5.hist(
210+
[start_date + i * time_delta for i in range(30)],
211+
bins=bin_edges,
212+
weights=values2
213+
)
214+
ax6.hist(
215+
[start_date + i * time_delta for i in range(30)],
216+
bins=bin_edges,
217+
weights=values3
218+
)
178219

179220
@pytest.mark.xfail(reason="Test for hist2d not written yet")
180221
@mpl.style.context("default")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy