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

Appearance settings

Commit 46e0dc2

Browse filesBrowse files
committed
datetime vs datetime, number vs datetime, datetime vs number
1 parent eb0ff88 commit 46e0dc2
Copy full SHA for 46e0dc2

File tree

Expand file treeCollapse file tree

1 file changed

+31
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-24
lines changed

‎lib/matplotlib/tests/test_datetime.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_datetime.py
+31-24Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,39 @@ def test_axvline(self):
5353
@mpl.style.context("default")
5454
def test_axvspan(self):
5555
mpl.rcParams["date.converter"] = 'concise'
56-
np.random.seed(19680801)
5756

5857
start_date = datetime.datetime(2023, 1, 1)
59-
time_delta = datetime.timedelta(days=1)
60-
61-
values1 = np.random.randint(1, 10, 30)
62-
values2 = np.random.randint(1, 10, 30)
63-
values3 = np.random.randint(1, 10, 30)
64-
65-
bin_edges = [start_date + i * time_delta for i in range(31)]
66-
67-
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True)
68-
69-
axes = [ax1, ax2, ax3]
70-
values_list = [values1, values2, values3]
71-
72-
for ax, values in zip(axes, values_list):
73-
ax.hist(
74-
[start_date + i * time_delta for i in range(30)],
75-
bins=bin_edges,
76-
weights=values
77-
)
78-
for i in range(np.random.randint(1, 5)):
79-
xmin = start_date + np.random.randint(0, 30) * time_delta
80-
xmax = xmin + np.random.randint(1, 3) * time_delta
81-
ax.axvspan(xmin=xmin, xmax=xmax, facecolor='green', alpha=0.5)
58+
dates = [start_date + datetime.timedelta(days=i) for i in range(31)]
59+
numbers = list(range(1, 32))
60+
61+
fig, (ax1, ax2, ax3) = plt.subplots(3, 1,
62+
constrained_layout=True,
63+
figsize=(10, 12))
64+
65+
ax1.plot(dates, numbers, marker='o', color='blue')
66+
for i in range(0, 31, 2):
67+
xmin = start_date + datetime.timedelta(days=i)
68+
xmax = xmin + datetime.timedelta(days=1)
69+
ax1.axvspan(xmin=xmin, xmax=xmax, facecolor='red', alpha=0.5)
70+
ax1.set_title('Datetime vs. Number')
71+
ax1.set_xlabel('Date')
72+
ax1.set_ylabel('Number')
73+
74+
ax2.plot(numbers, dates, marker='o', color='blue')
75+
for i in range(0, 31, 2):
76+
ax2.axvspan(xmin=i+1, xmax=i+2, facecolor='red', alpha=0.5)
77+
ax2.set_title('Number vs. Datetime')
78+
ax2.set_xlabel('Number')
79+
ax2.set_ylabel('Date')
80+
81+
ax3.plot(dates, dates, marker='o', color='blue')
82+
for i in range(0, 31, 2):
83+
xmin = start_date + datetime.timedelta(days=i)
84+
xmax = xmin + datetime.timedelta(days=1)
85+
ax3.axvspan(xmin=xmin, xmax=xmax, facecolor='red', alpha=0.5)
86+
ax3.set_title('Datetime vs. Datetime')
87+
ax3.set_xlabel('Date')
88+
ax3.set_ylabel('Date')
8289

8390
@pytest.mark.xfail(reason="Test for bar not written yet")
8491
@mpl.style.context("default")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.