LoginSignup
4
2

More than 3 years have passed since last update.

matplotlibの極座標プロットで,北が0度・時計回りのグラフを描く

Posted at

概要

極座標のプロットを描くには

ax = plt.subplot(111, polar=True)

のように polar=true を指定すればよいのですが、
デフォルトでは東が0度、反時計回りのプロットが描かれます。

polar1.png

方角ごとのデータを扱いたい場合などは北を0度、時計回りにしたいこともあります。
以下の通り設定すればOKです。

ax.set_theta_direction(-1)
ax.set_theta_zero_location("N")

コード

polar.py
import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0, 2*np.pi, 100) 
r = np.linspace(0, 120, 100) 

tt, rr = np.meshgrid(theta,r) 
z = rr 

ax = plt.subplot(111, polar=True)

ax.set_theta_direction(-1)
ax.set_theta_zero_location("N")

ctf = plt.contourf(tt, rr, z, 100)

plt.colorbar()
plt.show()

出力

polar2.png

素晴らしい。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2