Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
As found in #27490, while contour does appear to allow units, if you pass manual label locations to the manual argument of `clabel, it will fail.
contour
manual
import datetime import numpy as np import matplotlib.pyplot as plt # Sample data for contour plot dates = [datetime.datetime(2023, 10, 1) + datetime.timedelta(days=i) for i in range(10)] x_start, x_end, x_step = -10.0, 5.0, 0.5 y_start, y_end, y_step = 0, 10, 1 x = np.arange(x_start, x_end, x_step) y = np.arange(y_start, y_end, y_step) # In this case, Y axis has dates X, Y = np.meshgrid(x, dates) rows = len(X) cols = len(X[0]) z1D = np.arange(rows * cols) Z = z1D.reshape((rows, cols)) fig, ax = plt.subplots() CS = ax.contour(X, Y, Z) ax.clabel(CS, CS.levels, inline=True, fmt=dict(zip(CS.levels, dates)), manual=[(x, y) for x, y in zip(x, dates)])
Traceback (most recent call last): File "/home/elliott/code/matplotlib/clabel.py", line 27, in <module> ax.clabel(CS, CS.levels, inline=True, fmt=dict(zip(CS.levels, dates)), File "/home/elliott/code/matplotlib/lib/matplotlib/axes/_axes.py", line 6581, in clabel return CS.clabel(levels, **kwargs) File "/home/elliott/code/matplotlib/lib/matplotlib/contour.py", line 195, in clabel self.add_label_near(x, y, inline, inline_spacing) File "/home/elliott/code/matplotlib/lib/matplotlib/contour.py", line 553, in add_label_near x, y = transform.transform((x, y)) File "/home/elliott/code/matplotlib/lib/matplotlib/transforms.py", line 1508, in transform res = self.transform_affine(self.transform_non_affine(values)) File "/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py", line 297, in wrapper return func(*args, **kwargs) File "/home/elliott/code/matplotlib/lib/matplotlib/transforms.py", line 2422, in transform_affine return self.get_affine().transform(values) File "/home/elliott/code/matplotlib/lib/matplotlib/transforms.py", line 1797, in transform return self.transform_affine(values) File "/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py", line 297, in wrapper return func(*args, **kwargs) File "/home/elliott/code/matplotlib/lib/matplotlib/transforms.py", line 1868, in transform_affine return affine_transform(values, mtx) TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
Labels are added at spots corresponding to those given in manual.
No response
589d3fb
git checkout
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
As found in #27490, while
contour
does appear to allow units, if you pass manual label locations to themanual
argument of `clabel, it will fail.Code for reproduction
Actual outcome
Expected outcome
Labels are added at spots corresponding to those given in
manual
.Additional information
No response
Operating system
No response
Matplotlib Version
589d3fb
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
git checkout
The text was updated successfully, but these errors were encountered: