![見出し画像](https://assets.st-note.com/production/uploads/images/106312947/rectangle_large_type_2_c56ac26099d3731d727490bef1ccc8aa.png?width=800)
Photo by
golchiki
Google Colabでハートの図形を描く
ChatGTPの出力です。
問い:Google Colabでハートのグラフを描く方法を教えてください。
import matplotlib.pyplot as plt
import numpy as np
# ハートの曲線のデータを作成します
t = np.linspace(0, 2*np.pi, 1000)
x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t)
# ハートの曲線をプロットします
plt.plot(x, y, color='red', linewidth=2)
plt.axis('equal') # x軸とy軸のスケーリングを等しくします
plt.title('ハートのグラフ')
plt.show()
![](https://assets.st-note.com/img/1685258610457-fhkZSuCB6A.png?width=800)
![](https://assets.st-note.com/img/1685258670826-58Mh25Fw1P.png)
![](https://assets.st-note.com/img/1685258727567-kmarWTUi7j.png?width=800)
![](https://assets.st-note.com/img/1685258769502-87lxW5XeGb.png?width=800)
![](https://assets.st-note.com/img/1685258917566-uNoyjvpqpM.png?width=800)
![](https://assets.st-note.com/img/1685258945552-puo63OzQYn.png?width=800)
![](https://assets.st-note.com/img/1685259327033-EFITxWH72c.png?width=800)
import matplotlib.pyplot as plt
import numpy as np
import japanize_matplotlib
# ハートの曲線のデータを作成します
t = np.linspace(0, 2*np.pi, 1000)
x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t)
# ハートの曲線をプロットします
plt.plot(x, y, color='red', linewidth=2)
plt.axis('equal') # x軸とy軸のスケーリングを等しくします
plt.title('ハートのグラフ')
plt.show()
![](https://assets.st-note.com/img/1685259369711-1tdjVLLSpI.png?width=800)
この記事が気に入ったらサポートをしてみませんか?