Skip to content

plot(), cplot(), splot() show the previous blank graph windows when exception has been raised. #1007

Description

@haydenwong7bm

plot(), cplot(), splot() show the previous blank graph windows when exceptions have been raised until the successful run.

>>> plot(lambda t: 'a', (0, 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "*\Python312\Lib\site-packages\mpmath\visualization.py", line 62, in plot
    if ctx.isnan(v) or abs(v) > 1e300:
       ^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp.py", line 302, in isnan
    x = ctx.convert(x)
        ^^^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp_python.py", line 831, in convert
    return ctx._convert_fallback(x, strings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp.py", line 595, in _convert_fallback
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from 'a'
>>> plot(lambda t: t**2, (0, 2))
>>> plot(lambda t: 'a', (0, 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "*\Python312\Lib\site-packages\mpmath\visualization.py", line 62, in plot
    if ctx.isnan(v) or abs(v) > 1e300:
       ^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp.py", line 302, in isnan
    x = ctx.convert(x)
        ^^^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp_python.py", line 831, in convert
    return ctx._convert_fallback(x, strings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "*\Python312\Lib\site-packages\mpmath\ctx_mp.py", line 595, in _convert_fallback
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from 'a'
>>> cplot(lambda t: t, (0, 2))
Image Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions