質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Q&A

1回答

583閲覧

Matplotlibでの図形作成

maj

総合スコア2

Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

0グッド

0クリップ

投稿2020/07/15 09:48

前提・実現したいこと

pythonで国旗を作るシステムを作っています。
星を出力した時にエラーが発生しました。
なぜ出力されないのか教えてください。
エラーは最後から2行目です。

発生している問題・エラーメッセージ

AttributeError Traceback (most recent call last) <ipython-input-1-aaa0a3995766> in <module>() 42 ax.add_patch(p) 43 p=Polygon(xy=points_1,facecolor='y') ---> 44 ax.add_pacth(p) 45 plt_show() AttributeError: 'AxesSubplot' object has no attribute 'add_pacth'

該当のソースコード

import matplotlib.pyplot as plt from matplotlib.patches import Circle, Wedge, Polygon, Ellipse from math import sin, cos, pi def star_points(r,center): r2=r*sin(0.1*pi)/sin(0.3*pi) points=[] for deg in range(0,360,36): theta=(deg-90)/360*2*pi if deg % 72 ==0: x=r*cos(theta) y=-r*sin(theta) else: x=r2*cos(theta) y=-r2*sin(theta) points.append((x+center[0],y+center[1])) return points fig,ax=plt.subplots() ax.set_aspect('equal') unit=50 width,height=unit*50,unit*30 radius_1=unit*2 radius_2=unit*3 center_1=(unit*25,unit*15) center_2=(unit*25,unit*2) center_3=(unit*25,unit*28) center_4=(unit*33,unit*28) center_5=(unit*33,unit*2) center_6=(unit*17,unit*28) center_7=(unit*17,unit*2) points_1=star_points(radius_2,center_1) points_2=star_points(radius_1,center_2) points_3=star_points(radius_1,center_3) points_4=star_points(radius_1,center_4) points_5=star_points(radius_1,center_5) points_6=star_points(radius_1,center_6) points_7=star_points(radius_1,center_7) ax.set_xlim(0,width) ax.set_ylim(0,height) p=Polygon(xy=[(0,0),(width,0),(width,height),(0,height)],facecolor='r') ax.add_patch(p) p=Polygon(xy=[(unit*4,unit*4),(unit*4,unit*26),(unit*46,unit*4),(unit*46,unit*26)],facecolor='#008000') ax.add_patch(p) p=Polygon(xy=points_1,facecolor='y') ax.add_pacth(p) plt_show()

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

タイプミスが二箇所あります。

Python

1p=Polygon(xy=points_1,facecolor='y') 2#ax.add_pacth(p) 3ax.add_patch(p) 4#plt_show() 5plt.show()

投稿2020/07/15 11:16

meg_

総合スコア10579

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問