Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
if transform is None:
transform = self.axes.transData
if transform:
Comment thread
story645 marked this conversation as resolved.
x = self.axes.convert_xunits(x)
y = self.axes.convert_yunits(y)
x, y = transform.transform((x, y))

idx_level_min, idx_vtx_min, proj = self._find_nearest_contour(
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,17 @@ def test_bxp(self):
ax.xaxis.set_major_formatter(mpl.dates.DateFormatter("%Y-%m-%d"))
ax.set_title('Box plot with datetime data')

@pytest.mark.xfail(reason="Test for clabel not written yet")
@mpl.style.context("default")
def test_clabel(self):
dates = [datetime.datetime(2023, 10, 1) + datetime.timedelta(days=i)
for i in range(10)]
x = np.arange(-10.0, 5.0, 0.5)
X, Y = np.meshgrid(x, dates)
Z = np.arange(X.size).reshape(X.shape)

fig, ax = plt.subplots()
ax.clabel(...)
CS = ax.contour(X, Y, Z)
ax.clabel(CS, manual=[(x[0], dates[0])])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you test that the label is set to the expected value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure i can add an assertion on the label value, what would be the best way to check it, assert on the text string or the position?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!


@mpl.style.context("default")
def test_contour(self):
Expand Down
Loading