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

Appearance settings

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

Copy link
Copy link
Closed
@juergspaak

Description

@juergspaak
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.