| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
stem breaks when I specify the horizontal components with a PyTorch Tensor.
import torch
from matplotlib import pyplot as plt
x = torch.arange(10.)
y = (x * .2 * torch.pi).sin()
plt.plot(x, y) # works
plt.stem(x, y) # breaks
plt.stem(x.numpy(), y) # worksTypeError: min() received an invalid combination of arguments - got (out=NoneType, axis=NoneType, ), but expected one of:
* ()
* (Tensor other)
* (int dim, bool keepdim = False)
didn't match because some of the keywords were incorrect: out, axis
* (name dim, bool keepdim = False)
didn't match because some of the keywords were incorrect: out, axis
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[50], line 7
5 y = (x * .2 * torch.pi).sin()
6 plt.plot(x, y) # works
----> 7 plt.stem(x, y) # breaks
8 plt.stem(x.numpy(), y) # works
File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/pyplot.py:4085](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/pyplot.py#line=4084), in stem(linefmt, markerfmt, basefmt, bottom, label, orientation, data, *args)
4074 @_copy_docstring_and_deprecators(Axes.stem)
4075 def stem(
4076 *args: ArrayLike | str,
(...) 4083 data=None,
4084 ) -> StemContainer:
-> 4085 return gca().stem(
4086 *args,
4087 linefmt=linefmt,
4088 markerfmt=markerfmt,
4089 basefmt=basefmt,
4090 bottom=bottom,
4091 label=label,
4092 orientation=orientation,
4093 **({"data": data} if data is not None else {}),
4094 )
File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/__init__.py:1521](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/__init__.py#line=1520), in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
1518 @functools.wraps(func)
1519 def inner(ax, *args, data=None, **kwargs):
1520 if data is None:
-> 1521 return func(
1522 ax,
1523 *map(cbook.sanitize_sequence, args),
1524 **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})
1526 bound = new_sig.bind(ax, *args, **kwargs)
1527 auto_label = (bound.arguments.get(label_namer)
1528 or bound.kwargs.get(label_namer))
File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/axes/_axes.py:3216](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/matplotlib/axes/_axes.py#line=3215), in Axes.stem(self, linefmt, markerfmt, basefmt, bottom, label, orientation, *args)
3214 marker_x = locs
3215 marker_y = heads
-> 3216 baseline_x = [np.min(locs), np.max(locs)]
3217 baseline_y = [bottom, bottom]
3219 markerline, = self.plot(marker_x, marker_y,
3220 color=markercolor, linestyle=markerstyle,
3221 marker=markermarker, label="_nolegend_")
File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3301](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py#line=3300), in min(a, axis, out, keepdims, initial, where)
3189 @array_function_dispatch(_min_dispatcher)
3190 def min(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
3191 where=np._NoValue):
3192 """
3193 Return the minimum of an array or minimum along an axis.
3194
(...) 3299 6
3300 """
-> 3301 return _wrapreduction(a, np.minimum, 'min', axis, None, out,
3302 keepdims=keepdims, initial=initial, where=where)
File [/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:84](http://localhost:8888/opt/homebrew/Caskroom/miniconda/base/envs/book/lib/python3.13/site-packages/numpy/_core/fromnumeric.py#line=83), in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
82 return reduction(axis=axis, dtype=dtype, out=out, **passkwargs)
83 else:
---> 84 return reduction(axis=axis, out=out, **passkwargs)
86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
TypeError: min() received an invalid combination of arguments - got (out=NoneType, axis=NoneType, ), but expected one of:
* ()
* (Tensor other)
* (int dim, bool keepdim = False)
didn't match because some of the keywords were incorrect: out, axis
* (name dim, bool keepdim = False)
didn't match because some of the keywords were incorrect: out, axisMost of the time, matplotlib is capable of plotting tensors without issues.
PyTorch version: 2.7.0
No response
3.10.3
module://matplotlib_inline.backend_inline
3.13.5
4.4.3
conda
| Back | FazBrowse Home | New Git URL |
Activity
QuLogic commented on Jun 26, 2025
Always post the full traceback.
Atcold commented on Jun 26, 2025
@QuLogic, just added it. Thanks for checking in.
QuLogic commented on Jul 1, 2025
It's a bit unfortunate that torch Tensors don't properly implement the NumPy API.
BTW, does len(torch.arange(10.)) work correctly?
Check that stem input is 1D
QuLogic commented on Jul 1, 2025
Please try the linked PR.
Check that stem input is 1D
Atcold commented on Jul 11, 2025
Uh… yes?
By 'try the PR' you're suggesting to install matplotlib from source, yes?
QuLogic commented on Jul 12, 2025
Sure, or you could just apply the patch; it won't require rebuilding. Or you can pull the wheels from https://github.com/matplotlib/matplotlib/actions/runs/16100956663