繁体   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