Skip to content

Wrong/not useful error message when plotting incompatible x and y #20452

@juergspaak

Description

@juergspaak

When plotting plt.plot(np.ones(10), np.ones((10,0)) it raises a ZeroDivisionError, which confused me much.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

plt.plot(np.ones(10), np.ones((10,0)))

This raises the error:

ZeroDivisionError: integer division or modulo by zero

Expected outcome

I think however, it should either raise a ValueError, similar to plotting plt.plot(np.ones(2), np.ones(10)), i.e. something of the form:
ValueError: x and y must have same first dimension, but have shapes (10,) and (10, 0)

An alternative would be not ploting anything (similar to the behaviour of plt.plot(np.nan, np.nan) ) and potentially raise a warning.

Matplotlib version
Matplotlib version 3.3.2
module://ipykernel.pylab.backend_inline

Python version 3.8.5

[@tacaswell edited to add markup]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions