私はPythonの初心者ですので、あまりにも些細なことがあればごめんなさい。同じ図形の複数の省略記号をテキストファイルのデータを使ってプロットする
これは、テキストファイルの最初の2行の例です。
RA 12月major_axis minor_axisは、ファイルの各行は、1つの楕円をプロットするために必要とされる5つのパラメータを有する
149.20562 2.29594 0.00418 0.00310 83.40
をposition_angle。最初の2つの列は中央の列です。次の3つの列はそれぞれ長軸、短軸および位置角です。このファイルは、多数の行を持つ巨大なカタログの一部です。私はそれらの楕円をすべて1つの図にプロットしたい。
これは私が試みたものです。
import matplotlib.pyplot as plt
import numpy as np
import astropy.io.ascii as asciitable
from matplotlib.patches import Ellipse
path=/users/vishnu/Desktop/
fw=open(path + 'data_plot.txt', 'r')
table = asciitable.read(path+ "data_plot.txt")
ra_degrees=[table['ra']]
dec_degrees=[table['dec']]
major_axis_deg=[table['major_axis']]
minor_axis_deg=[table['minor_axis']]
position_angle_deg=[table['position_angle']]
for ra, dec, w, h, angle in zip(ra_degrees,
dec_degrees,major_axis_deg, minor_axis_deg, position_angle_deg):
ellipse = Ellipse(xy=(ra, dec), width=w, height=h, angle=angle)
ax.add_patch(ellipse)
plt.axis('scaled')
plt.show()
fw.close()
これはエラーログです。
runfile('/users/vishnu/.spyder2-py3/radio_sources.py', wdir='/users/vishnu/.spyder2-py3')
Traceback (most recent call last):
File "<ipython-input-299-a0011c0326f5>", line 1, in <module>
runfile('/users/vishnu/.spyder2-py3/radio_sources.py', wdir='/users/vishnu/.spyder2-py3')
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "https://stackoverflow.com/users/vishnu/.spyder2-py3/radio_sources.py", line 63, in <module>
ax.add_patch(ellipse)
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_base.py", line 1783, in add_patch
self._update_patch_limits(p)
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_base.py", line 1803, in _update_patch_limits
xys = patch.get_patch_transform().transform(vertices)
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/matplotlib/patches.py", line 1409, in get_patch_transform
self._recompute_transform()
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/matplotlib/patches.py", line 1398, in _recompute_transform
.scale(width * 0.5, height * 0.5) \
File "https://stackoverflow.com/users/vishnu/anaconda3/lib/python3.5/site-packages/matplotlib/transforms.py", line 1965, in scale
np.float_)
ValueError: setting an array element with a sequence.
これを行うには、配列を作成する必要がなく、よりスマートな方法があれば教えてください。
完全なトレースバックを送信します。特に、エラーの原因となったコードの行は何ですか? –
私は今投稿を更新しました。 – Vishnu