前提・実現したいこと
質問失礼します。
以下のようなtxtファイルを読み込んで、1~6のそれぞれの数字の最長距離(線分の長さ)を調べてmatplotlibでプロットしたいと考えています。
例えば、"6"の距離を調べたい場合、六の出現場所は、bottom[0], bottom[2], bottom[3]で、それぞれのindexを調べて最長の距離を求めるというものです。
txt
top = [1 ,0, 3, 1, 4, 2, 3, 2] bottom = [6, 4, 6, 6, 3, 0, 5, 5]
1~6それぞれの数字の最長距離をfor文で回してmatplotlibで表示させたいのですが、以下のようなエラーが出てしまいました。
axis 2というのは3次元のことで、なぜ2次元の話をしているのにこのようなエラーが出るのかがわかりません。
よろしくお願いします。
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- AxisError Traceback (most recent call last) <ipython-input-80-1b52cd787767> in <module> 46 47 if __name__ == '__main__': ---> 48 main() 49 50 <ipython-input-80-1b52cd787767> in main() 39 print("bottom : ", bottom) 40 ---> 41 le.h_seg(1) 42 43 <ipython-input-80-1b52cd787767> in h_seg(self, num) 24 25 plt.hlines(1, int(concat.min(1)), int(concat.max(1))) ---> 26 plt.hlines(2, int(concat.min(2)), int(concat.max(2))) 27 28 plt.show() /Applications/anaconda3/lib/python3.8/site-packages/numpy/core/_methods.py in _amin(a, axis, out, keepdims, initial, where) 41 def _amin(a, axis=None, out=None, keepdims=False, 42 initial=_NoValue, where=True): ---> 43 return umr_minimum(a, axis, None, out, keepdims, initial, where) 44 45 def _sum(a, axis=None, dtype=None, out=None, keepdims=False, AxisError: axis 2 is out of bounds for array of dimension 2
該当のソースコード
python
#一部抜粋 def h_seg(self, num): top_index = np.where(np.array(top) == num) bottom_index = np.where(np.array(bottom) == num) concat = np.concatenate([top_index, bottom_index], axis=1) plt.hlines(1, int(concat.min(1)), int(concat.max(1))) plt.hlines(2, int(concat.min(2)), int(concat.max(2))) plt.show() def main(): with open("routing.txt") as f: reader = csv.reader(f) l = [list(map(int, row)) for row in reader] le = left_edge(l[0], l[1]) le.h_seg() return 0
まだ回答がついていません
会員登録して回答してみよう