Skip to content
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

Low resolution with imshow #475

Open
elkfraaf opened this issue Sep 24, 2020 · 4 comments
Open

Low resolution with imshow #475

elkfraaf opened this issue Sep 24, 2020 · 4 comments

Comments

@elkfraaf
Copy link

Hi,

I'm trying to use mpld3 for generating interactive html for my figures. I'm using simple code as following:

import matplotlib.pyplot as plt
import numpy as np

import mpld3

fig, ax = plt.subplots()

X = np.random.rand(32, 32)

im = ax.imshow(X, aspect="auto", interpolation="none", origin="lower")

ax.set_title('An Image', size=20)

fig.savefig('example.png')

mpld3.show()

The saved image from the line fig.savefig('example.png') is as following:
example

While using mpld3.show() results in a very low resolution image as following:
mpld3_low_res

I don't know why mpld3 generates such low resolution images. Anyone knows how to fix this?

Thanks,
Ayman

@cliffckerr
Copy link
Member

Hi Ayman -- I'm not sure off the top of my head why the interpolation arg is being ignored, but a workaround is to use pcolor() instead of imshow():

import matplotlib.pyplot as plt
import numpy as np

import mpld3

fig, ax = plt.subplots()

X = np.random.rand(32, 32)

im = ax.pcolor(X)
ax.set_aspect(1)

ax.set_title('An Image', size=20)

fig.savefig('example.png')

mpld3.show()

A little fiddling with the x-tick labels and it should give you an identical result to imshow(). I'll leave this issue open since there shouldn't need to be a workaround, it should just work!

@elkfraaf
Copy link
Author

Thanks @cliffckerr for your reply. pcolor generates exactly what I'm looking for. I also used pcolormesh before which I believe is the same as pcolor. I hope so there is a solution for using imshow normally.

@brjdenis
Copy link

Hi there. If there is any chance of fixing this I am adding a vote. Imshow works better for large arrays.

@nikhbikh
Copy link

Also facing this same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants