Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Modifying NumPy array after passing to set_xticks() unexpectedly alters plot ticks #32313

Description

@williamlus

Bug summary

When passing a NumPy array to ax.set_xticks(), Matplotlib retains a reference to the array instead of creating a copy. Any in-place modifications made to the array after calling set_xticks() directly mutate the plot's tick locations. Passing a standard Python list does not exhibit this issue, suggesting Matplotlib should create an explicit copy of array input internally.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

attributes = ['Speed', 'Reliability', 'Comfort', 'Safety', 'Efficiency']
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1, projection='polar')
theta = np.linspace(0, 2*np.pi, 5, endpoint=False)
# theta = np.linspace(0, 2*np.pi, 5, endpoint=False).tolist() # this works
ax1.set_xticks(theta)
ax1.set_xticklabels(attributes)
for i in range(5): theta[i] += np.pi * 2

Actual outcome

Image

Expected outcome

Image

Additional information

No response

Operating system

No response

Matplotlib Version

0.2.0.dev55193+unknown.g2153774ae

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions