0

I am trying to plot an array full of ones and zeros and most of the time it works well and looks like this.

However, when my array becomes too big (I need to plot 60,000x70) the plot only draws part of the data.

At first I thought that this might be some sort of memory issue, but the arrays actually are not that big after all and when looking into memory usage there also was no sign of too heavy lifting.

It becomes really weird, however, when I plot the transposed array, because then it works like a breeze.

I looked around in forums quite a lot but apparently nobody else has had such an issue. Might this be a bug? I really need to plot it in the original orientation. So, any help is highly appreciated. Thanks in advance!

UPDATE

This exactly reproduces my problem:

import numpy as np
import matplotlib.pyplot as plt

# generate fake data
a = np.random.random((60000, 70))
for x in np.nditer(a, op_flags=['readwrite']):
    if x > 0.9:
        x[...] = 1
    else:
        x[...] = 0

# plot fake data
fig, axes = plt.subplots(2, 2)
axes[0][0].imshow(a, interpolation='none', cmap='binary', aspect='auto')
axes[0][1].imshow(a.T, interpolation='none', cmap='binary', aspect='auto')
axes[1][0].imshow(a[:30000], interpolation='none', cmap='binary', aspect='auto')
axes[1][1].imshow(a[:30000].T, interpolation='none', cmap='binary', aspect='auto')
plt.show()

The code yields this. In the upper left subplot everything is plotted. In the plot showing the transposed array (upper right), however, matplotlib only draws the first ~10000 columns. The lower two plots just show the first half of the array (left normal, right transposed) and as you can see, with smaller arrays there is no issue.

SOLVED

This problem does not occur with matplotlib 2.x

6
  • This naive attempt at reproducing the problem fails (at least for me). Can you help us construct a reproducible example? What is the dtype of a? Why is there a pandas tag on this question? How is pandas involved? (Transposing DataFrames can change its columns' dtypes...) Commented Feb 13, 2018 at 18:40
  • Please read and understand minimal reproducible example. Then edit your question accordingly. Commented Feb 13, 2018 at 18:40
  • The expectation to accurately map 60000 datapoints correctly to ~1000 screenpixels is probably just a bit overoptimistic. Commented Feb 13, 2018 at 18:53
  • Sorry for hot having included an reproducible example, I have added one now. The pandas tag was a mistake. Commented Feb 14, 2018 at 0:33
  • The output of the code from the question looks like this for me - just as expected. This may be an issue of using an old matplotlib version, or a different backend. Commented Feb 14, 2018 at 0:44

1 Answer 1

1

[SOLVED] The problem only occurs with outdated versions of matplotlib.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.