Mac์์๋ง imshow๋ก ์์ฑ ๋ 2D ์ด๋ฏธ์ง์ ์ปฌ๋ฌ ๋ฐ๋ฅผ ์ถ๊ฐ ํ ๋ ๋ฐ์ํฉ๋๋ค.
mpld3 .__ version __ = '0.3.1.dev1'(์ด์ ๋ฒ์ ์์๋ ์คํจ)
matplotlib .__ version __ = '2.1.0'
import matplotlib.pyplot as plt, mpld3
import numpy as np
fig,ax=plt.subplots(1,1)
im=ax.imshow(np.zeros((100,100)))
fig.colorbar(im, ax=ax)
mpld3.fig_to_html(fig)
๋๋ ๋ํ ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. Python 2.7.4, mpld3 v0.2 ๋ฐ matplotlib v2.1.2๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๋๋ ๋ฌธ์ ๊ฐ matplotlib์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ต์ ๋ฒ์ ์ matplotlib์ ํธํ๋๋๋ก mpld3๋ฅผ ์ ๋ฐ์ดํธ ํ ๊ณํ์ด ์์ต๋๊น?
์ด ๋ฌธ์ ์ ๋ํ ์์ ์ฌํญ์ ์ฐพ์์ต๋๋ค. Lib \ site-packages \ mpld3์์๋ _display.py ํ์ผ์ ํธ์งํ๊ณ NumpyEncoder ํด๋์ค๋ฅผ ๋ค์์ผ๋ก ๋์ฒด ํ ์ ์์ต๋๋ค.
class NumpyEncoder(json.JSONEncoder):
""" Special json encoder for numpy types """
def default(self, obj):
if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
numpy.uint16,numpy.uint32, numpy.uint64)):
return int(obj)
elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32,
numpy.float64)):
return float(obj)
try: # Added by ceprio 2018-04-25
iterable = iter(obj)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
matplotlib ๋ฒ์ 2.2.3์ ๊ฒฝ์ฐ ์ ํญ์ numpy ๋ฐฐ์ด์์ mpld3.mpld3renderer.MPLD3Renderer.draw_path_collection์ ๋ชฉ๋ก์ผ๋ก ๋ณํํ๊ธฐ์ ์ถฉ๋ถํ๋ค๋ ๊ฒ์ ์์์ต๋๋ค.
์ต์ ๋ฒ์ ์ ์ฌ์ ํ ๋ฌธ์
@jonashaag @ceprio ๋์ด 2018 ๋ 4 ์ 26 ์ผ ์์ ๋๊ธ์ ๋ฌ์
์๋ ํ์ธ์ @jonashaag ๋ฐ @JupyterJones , https://github.com/sciris/mpld3 ์์๋ ๋ฌธ์ ๊ฐ ์๋์ง ํ์ธํ ์
@ceprio ์ ์ฝ๋ฉํธ๋ ์ ์๊ฒ
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ๋ฌธ์ ์ ๋ํ ์์ ์ฌํญ์ ์ฐพ์์ต๋๋ค. Lib \ site-packages \ mpld3์์๋ _display.py ํ์ผ์ ํธ์งํ๊ณ NumpyEncoder ํด๋์ค๋ฅผ ๋ค์์ผ๋ก ๋์ฒด ํ ์ ์์ต๋๋ค.