Skip to content

Unable to append to array.array after using it in a plot #16935

@MichaelClerx

Description

@MichaelClerx

I'm running simulations and logging the output to array.array objects. After I use one of these to plot results, the array's append() method stops working.

It seems something in matplotlib's plotting code causes the array to "export a buffer"

Code for reproduction

#!/usr/bin/env python3
import array
import matplotlib.pyplot as plt

x = array.array('d')
y = array.array('d')

# Appending to array works as expectecd
for i in range(10):
    x.append(i)
    y.append(i**2)

# Now using x and y in a plot
plt.figure()
plt.plot(x, y)

# Side effect has occurred: no longer able to append to array
x.append(11)

Actual outcome

Traceback (most recent call last):
  File "./log_append.py", line 15, in <module>
    x.append(11)
BufferError: cannot resize an array that is exporting buffers

Expected outcome

No errors

Matplotlib version

  • Operating system: Fedora linux
  • Matplotlib version: 3.0.3
  • Matplotlib backend (print(matplotlib.get_backend())): template, Agg
  • Python version: 3.7.6
  • Other libraries: Myokit (pip installable)

Matplotlib installed via dnf (package manager)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueskeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions