2017-06-01 79 views
1

我想繪製一個使用matplotlib的極座標圖。如何在外圍線上添加刻度的刻度標記?如何在極軸的周界線上添加刻度標記?

import matplotlib.pyplot as plt 
fig = plt.figure(figsize=(30, 30)) 
ax = plt.subplot(111, polar=True) 
ax.set_rmax(1) 
plt.show() 

grades, have no ticks

應該有這樣的標誌物(解僱的彩色數據): polar plot

我已經與set_xtickstickslabelthethagrid嘗試。但我找不到解決方案。

請幫忙。

回答

1

似乎沒有在matplotlib中實現的徑向刻度標記(只有刻度標籤)。如果你不介意,你可能想考慮自己創建它們。例如:

import numpy as np 
import matplotlib.pyplot as plt 

ax = plt.subplot(111, polar=True) 
ax.xaxis.get_gridlines()[2].set_linestyle('-') 

# Make ticks 
tick_length = 0.5 
start_theta = np.pi * 0.5 
for i in range(0, 42, 2): 
    end_r = np.sqrt(i ** 2 + tick_length ** 2) 
    if i == 0: 
     end_theta = 0 
    else: 
     end_theta = start_theta - np.arctan(tick_length/i) 
    ax.plot([start_theta, end_theta], [i, end_r], color='k') 

ax.set_rmax(40) 
ax.set_rticks(range(0, 41, 10)) 
ax.set_rlabel_position(90) 
for t in ax.yaxis.get_major_ticks(): 
    t.label1.set_va('center') 
    t.label1.set_ha('right') 

plt.show() 

enter image description here

相關問題