簡體   English   中英

在python中使用極坐標圖進行笛卡爾縮放

[英]Cartesian zoom with polar plot in python

我正在嘗試在極坐標中繪制一些數據(我目前正在使用極坐標投影): 極坐標中的數據

我使用的代碼如下:

import matplotlib.pyplot as plt
import numpy as np

# Create radial and angular array
r = np.linspace(1.0,10,11)
t = np.linspace(0.0,0.5*np.pi,101)

# Define the quantity that I want to plot
z = np.zeros((len(t),len(r)))
for yval in range(len(r)):
  z[:,yval] = np.cos(16.0*t)/r[yval]

#Create the figure
f = plt.figure(figsize=(13,8))
ax = plt.subplot(111, projection='polar')
ax.set_rorigin(-1)

#Plot the data
pcm = ax.pcolormesh(t,r,z.T,cmap = 'hot',shading='gouraud')
ax.set_xlim([0.0,0.5*np.pi])
ax.set_ylim([1.0,10.0])

#Add colorbar and show
bar = f.colorbar(pcm)
plt.show()

到目前為止,我沒有問題,但我想放大該圖的特定區域。 但是,當我設置軸范圍時,軸仍然是極坐標,因此我無法放大域的“笛卡爾”區域(即方框)。

一個可能的選擇是將數據轉換為笛卡爾坐標,但是當我這樣做時,我會在域的內部失去很多分辨率,這是我絕對應該避免的。

如何在不手動轉換數據的情況下選擇極坐標圖中的矩形區域? 如果我必須切換到笛卡爾坐標,是否有任何 matplotlib 或 python 函數可以在處理域內部區域的分辨率時執行此操作? 提前致謝

您可以自己創建一個 X、Y 網格,該網格在域的內部具有更高的分辨率,並將其與ax.pcolormesh() 一起使用

# Create radial and angular array
r = np.linspace(1.0,10,11)
t = np.linspace(0.0,0.5*np.pi,101)

# Define the quantity that I want to plot
z = np.zeros((len(t),len(r)))
for yval in range(len(r)):
    z[:,yval] = np.cos(16.0*t)/r[yval]


#Create the figure, bigger figsize to make the resulting plot square
f = plt.figure(figsize=(13,10))
ax = plt.subplot(111) # Drop back to XY coordinates


# Generate the XY corners of the colormesh
X = np.array([[ri*np.cos(j) for j in t] for ri in r])
Y = np.array([[ri*np.sin(j) for j in t] for ri in r])

#Plot the data
pcm = ax.pcolormesh(X,Y,z.T,cmap = 'hot',shading='gouraud')

#Add colorbar and show
bar = f.colorbar(pcm)
plt.show()

問題中的圖

上面代碼生成的圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM