簡體   English   中英

極坐標圖 x 軸 label position 使用 matplotlib

[英]Polar chart x-axis label position using matplotlib

使用極坐標圖來表示一些數據,我希望標簽(當前位於 x 軸正上方)位於數據段上方。 所以就在軸之間。

我找到了多篇關於如何旋轉所有內容的文章,但它始終將 label 保持在軸的正上方。

我為軸准備的代碼的和平(如果您需要整個定義/代碼,請這樣說):

# Set axis names and orientation
ax.set_theta_zero_location("N")
ax.set_xticklabels(['Seg 1', 'Seg 2', 'Seg 3', 'Seg 4', 'Seg 5', 'Seg 6', 'Seg 7', 'Seg 8'])
ax.set_ylim((0, 10.0))
ax.set_rgrids([5,10], angle=22)

它產生的當前圖像:

在此處輸入圖像描述

現在我想將標簽'Seg 1''Seg 2'等從軸移動到軸之間的右側。

您可以通過在小刻度上設置標簽來做到這一點,然后將小刻度寬度設置為零,這樣您就看不到它們了:

import matplotlib.ticker as ticker

# Set the major and minor tick locations
ax.xaxis.set_major_locator(ticker.MultipleLocator(np.pi/4))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(np.pi/8))

# Turn off major tick labels
ax.xaxis.set_major_formatter(ticker.NullFormatter())

# Set the minor tick width to 0 so you don't see them
for tick in ax.xaxis.get_minor_ticks():
    tick.tick1line.set_markersize(0)
    tick.tick2line.set_markersize(0)
    tick.label1.set_horizontalalignment('center')

# Set the names of your ticks, with blank spaces for the major ticks
ax.set_xticklabels(['','','Seg 1','','Seg 2','','Seg 3','','Seg 4','','Seg 5','','Seg 6','','Seg 7','','Seg 8'],minor=True)

暫無
暫無

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

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