Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Bug]: ValueError when plotting 2D pytorch tensor using matplotlib==3.8.0 #26806

Closed
@CMGeldenhuys

Description

@CMGeldenhuys

Bug summary

Value error occurs when trying to plot a 2D pytorch tensor usingmatplotlib==3.8.0. The error does not arise inmatplotlib==3.7.3.

Code for reproduction

# Using matplotlib==3.8.0>>>importtorch>>>importmatplotlibasmplt>>>mplt.__version__'3.8.0'>>>importmatplotlib.pyplotasplt>>>a=torch.randn(185,5)>>>plt.plot(a)Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>File".../lib/python3.11/site-packages/matplotlib/pyplot.py",line3578,inplotreturngca().plot(^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/axes/_axes.py",line1721,inplotlines= [*self._get_lines(self,*args,data=data,**kwargs)]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/axes/_base.py",line303,in__call__yieldfromself._plot_args(^^^^^^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/axes/_base.py",line496,in_plot_argsaxes.yaxis.update_units(y)File".../lib/python3.11/site-packages/matplotlib/axis.py",line1706,inupdate_unitsconverter=munits.registry.get_converter(data)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/units.py",line183,inget_converterfirst=cbook._safe_first_finite(x)^^^^^^^^^^^^^^^^^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/cbook.py",line1730,in_safe_first_finiteifsafe_isfinite(val):^^^^^^^^^^^^^^^^^^File".../lib/python3.11/site-packages/matplotlib/cbook.py",line1699,insafe_isfinitereturnmath.isfinite(val)^^^^^^^^^^^^^^^^^^ValueError:onlyoneelementtensorscanbeconvertedtoPythonscalars>>>b=torch.randn(185)>>>plt.plot(b)[<matplotlib.lines.Line2Dobjectat0x7f27d7ccc190>]# Using matplotlib==3.7.3>>>importtorch>>>importmatplotlibasmplt>>>mplt.__version__'3.7.3'>>>importmatplotlib.pyplotasplt>>>a=torch.randn(185,5)>>>plt.plot(a)[<matplotlib.lines.Line2Dobjectat0x7f19762d7910>,<matplotlib.lines.Line2Dobjectat0x7f1976684250>,<matplotlib.lines.Line2Dobjectat0x7f19764d5150>,<matplotlib.lines.Line2Dobjectat0x7f197598f9d0>,<matplotlib.lines.Line2Dobjectat0x7f19762bff50>]

Actual outcome

(included REPL output in above example)

Expected outcome

Expect 5 line series (one for each of the second dimension of the tensor)

Additional information

The bug seems to occur in version 3.8.0. (In both cases I was usingtorch==2.0.1)

Operating system

Ubuntu

Matplotlib Version

3.8.0 and 3.7.3

Matplotlib Backend

TkAgg

Python version

Python 3.11.5

Jupyter version

N/A

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp