4

matplotlib を使用して特定のプロットを複製しようとしています。次のようになります。

最終プロット

PolarAxes を使用して放射状の点を描画できることがわかりました。たとえば、次のスニペットを使用して非常に単純な極座標プロットを作成しました。

import matplotlib.pyplot as plt
fig = plt.figure()
# Set the axes as polar
ax = fig.add_subplot(111, polar=True)
# Draw some points
ax.plot([0],[1], 'o')
ax.plot([3],[1], 'o')
ax.plot([6],[1], 'o')

# Go clockwise
ax.set_theta_direction(-1)
# Start from the top
ax.set_theta_offset(1.570796327)

plt.savefig('test.png')

そして、私はこのようなものを手に入れます:

最初の例

私の質問は、最初の図のように線を引き、全周に収まるように幅を調整する方法はありますか? また、色を処理する方法に関するいくつかのヒントも大歓迎です。

更新:プロットする必要があるデータは非常に単純です。各トラックは、範囲が 0 から 9 の浮動小数点数の配列です (色はカラーマップ RdYlGn から派生します)。配列の長さは 96 の倍数です。

更新2:それは私が使用した切り取りです

# mydata is a simple list of floats
a = np.array([[x for i in range(10)] for x in mydata])

# construct the grid
radius = np.linspace(0.2,0.4,10)
theta = np.linspace(0,2*np.pi,len(a))
R,T  = np.meshgrid(radius,theta)

fig = plt.figure()
ax = fig.add_subplot(111, polar = True)

# plot the values using the appropriate colormap
ax.pcolor(T,R,a,cmap=cm.RdYlGn)
4

1 に答える 1

7

データがどのように編成されているかについての詳細がなければ、このプロットを再作成するための最良の方法を言うことは困難です。極座標プロットにさまざまな幅と色の線を描くのは簡単です。ただし、例のように多くが必要な場合は、処理が遅くなる可能性があります。極性疑似カラープロットの例も提供しました。

import numpy as np
import matplotlib.pyplot as plt

#Create radius and theta arrays, and a 2d radius/theta array
radius = np.linspace(0.2,0.4,51)
theta = np.linspace(0,2*np.pi,51)
R,T  = np.meshgrid(radius,theta)

#Calculate some values to plot
Zfun = lambda R,T: R**2*np.cos(T)
Z = Zfun(R,T)

#Create figure and polar axis
fig = plt.figure()
ax = fig.add_subplot(111, polar = True)

ax.pcolor(T,R,Z)    #Plot calculated values

#Plot thick red section and label it
theta = np.linspace(0,np.pi/4,21)
ax.plot(theta,[1.23 for t in theta],color='#AA5555',linewidth=10)   #Colors are set by hex codes
ax.text(np.pi/8,1.25,"Text")

ax.set_rmax(1.25)   #Set maximum radius

#Turn off polar labels
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)

プロット

于 2012-10-09T19:21:50.367 に答える