アナコンダのプロンプトでコードを書いたが、
%matplotlib inline でエラーをおこす。
このコードはターミナルで画像を表示するみたい?だが、当然windowsのプロンプトでは
無理だろう。
アナコンダからipythonを起動させそこからコードをかいていくと、上のコードがとおり
画像が表示できた。しかし以下のエラーがでた。
画像はでたが ヒストグラムでエラーする
# coding: UTF-8
#http://www.astropy.org/astropy-tutorials/FITS-images.html
#
import numpy as np
%config InlineBackend.rc = {}
import matplotlib
matplotlib.rc_file("M:/OneDrive/myprg_main/matplotlib/templates/matplotlibrc")
import matplotlib.pyplot as plt
%matplotlib inline
from astropy.utils.data import download_file
from astropy.io import fits
image_file = download_file('http://data.astropy.org/tutorials/FITS-images/HorseHead.fits', cache=True )
hdu_list = fits.open(image_file)
hdu_list.info()
#一般に画像情報は以下の場所にあるらしい
#データは、現在2次元numpyの配列として格納されています
image_data = hdu_list[0].data
image_data = fits.getdata(image_file)
print(type(image_data))
print(image_data.shape)
print(image_data)
hdu_list.close()
#画像表示
plt.imshow(image_data, cmap='gray')
plt.colorbar()
#ヒストグラム
#ヒストグラム作成するにmatplotlib.pyplot.hist()私は何か
#一次元に配列に2-Dからのデータをキャストする必要があります。
print(type(image_data.flat))
NBINS = 1000
histogram = plt.hist(image_data.flat, NBINS)
Filename: C:\Documents and Settings\moto\.astropy\cache\download\2c9202ae878ecfcb60878ceb63837f5f
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 161 (891, 893) int16
1 er.mask TableHDU 25 1600R x 4C [F6.2, F6.2, F6.2, F6.2]
<type 'numpy.ndarray'>
(893, 891)
[[ 7201 6642 6642 ..., 9498 9498 10057]
[ 6642 6363 6642 ..., 10057 10616 10616]
[ 6922 6642 6922 ..., 10337 11175 10616]
...,
[ 5412 5132 5412 ..., 13000 12580 12021]
[ 5796 5517 5796 ..., 12546 12546 11987]
[ 5796 5796 6076 ..., 11987 12546 12546]]
<type 'numpy.flatiter'>
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-f3027ba6c0c9> in <module>()
36 print(type(image_data.flat))
37 NBINS = 1000
---> 38 histogram = plt.hist(image_data.flat, NBINS)
k:\Anaconda2\lib\site-packages\matplotlib\pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
2956 histtype=histtype, align=align, orientation=orientation,
2957 rwidth=rwidth, log=log, color=color, label=label,
-> 2958 stacked=stacked, data=data, **kwargs)
2959 finally:
2960 ax.hold(washold)
k:\Anaconda2\lib\site-packages\matplotlib\__init__.pyc in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
k:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
5958 x = np.array([[]])
5959 else:
-> 5960 x = _normalize_input(x, 'x')
5961 nx = len(x) # number of datasets
5962
k:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.pyc in _normalize_input(inp, ename)
5889 """
5890 if (isinstance(x, np.ndarray) or
-> 5891 not iterable(cbook.safe_first_element(inp))):
5892 # TODO: support masked arrays;
5893 inp = np.asarray(inp)
k:\Anaconda2\lib\site-packages\matplotlib\cbook.pyc in safe_first_element(obj)
2540 def safe_first_element(obj):
2541 if isinstance(obj, collections.Iterator):
-> 2542 raise RuntimeError("matplotlib does not support generators "
2543 "as input")
2544 return next(iter(obj))
RuntimeError: matplotlib does not support generators as input
Filename: C:\Documents and Settings\moto\.astropy\cache\download\2c9202ae878ecfcb60878ceb63837f5f
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 161 (891, 893) int16
1 er.mask TableHDU 25 1600R x 4C [F6.2, F6.2, F6.2, F6.2]
<type 'numpy.ndarray'>
(893, 891)
[[ 7201 6642 6642 ..., 9498 9498 10057]
[ 6642 6363 6642 ..., 10057 10616 10616]
[ 6922 6642 6922 ..., 10337 11175 10616]
...,
[ 5412 5132 5412 ..., 13000 12580 12021]
[ 5796 5517 5796 ..., 12546 12546 11987]
[ 5796 5796 6076 ..., 11987 12546 12546]]
<type 'numpy.flatiter'>
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-f3027ba6c0c9> in <module>()
36 print(type(image_data.flat))
37 NBINS = 1000
---> 38 histogram = plt.hist(image_data.flat, NBINS)
k:\Anaconda2\lib\site-packages\matplotlib\pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
2956 histtype=histtype, align=align, orientation=orientation,
2957 rwidth=rwidth, log=log, color=color, label=label,
-> 2958 stacked=stacked, data=data, **kwargs)
2959 finally:
2960 ax.hold(washold)
k:\Anaconda2\lib\site-packages\matplotlib\__init__.pyc in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
k:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
5958 x = np.array([[]])
5959 else:
-> 5960 x = _normalize_input(x, 'x')
5961 nx = len(x) # number of datasets 5962
k:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.pyc in _normalize_input(inp, ename)
5889 """
5890 if (isinstance(x, np.ndarray) or
-> 5891 not iterable(cbook.safe_first_element(inp))):
5892 # TODO: support masked arrays;
5893 inp = np.asarray(inp)
k:\Anaconda2\lib\site-packages\matplotlib\cbook.pyc in safe_first_element(obj)
2540 def safe_first_element(obj):
2541 if isinstance(obj, collections.Iterator):
-> 2542 raise RuntimeError("matplotlib does not support generators "
2543 "as input")
2544 return next(iter(obj))
RuntimeError: matplotlib does not support generators as input
0 件のコメント:
コメントを投稿