Skip to content

[Bug]: matplotlib.pyplot.matshow "(first dimension of the array) are displayed horizontally" but are displayed vertically #27852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tkuraku opened this issue Mar 4, 2024 · 2 comments · Fixed by #27857
Labels
Documentation: API files in lib/ and doc/api
Milestone

Comments

@tkuraku
Copy link

tkuraku commented Mar 4, 2024

Bug summary

matshow states that "(first dimension of the array) are displayed horizontally": https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.matshow.html#matplotlib-pyplot-matshow. However it seems that the first dimension is vertically.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt


nx = 15
ny = 21

img = np.zeros((nx, ny))

for i in range(nx):
    for j in range(ny):
        if j == i:
            img[i, j] = 1

plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(img)
plt.title('imshow')
plt.subplot(1, 2, 2)
plt.matshow(img, fignum=0)
plt.title('matshow')
plt.show()

Actual outcome

First dimension is shown vertically

Expected outcome

I would expect that the first dimension be show horizontally according to the documentation.

Additional information

No response

Operating system

Debian 12

Matplotlib Version

3.8.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.12

Jupyter version

No response

Installation

conda

@tkuraku
Copy link
Author

tkuraku commented Mar 4, 2024

Screenshot from 2024-03-03 18-12-57

@timhoffm
Copy link
Member

timhoffm commented Mar 4, 2024

I believe the description is just wrong. Matrix indices are (row, column) and that’s what matshow displays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: API files in lib/ and doc/api
Projects
None yet
3 participants