mpld3 / mpld3

An interactive data visualization tool which brings matplotlib graphics to the browser using D3.

Home Page:http://mpld3.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Low resolution with imshow

elkfraaf opened this issue · comments

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

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!

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.

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

Also facing this same issue