python matplolib极坐标图x轴标签位置 [英] python matplolib polar chart x-axis label position

查看:2632
本文介绍了python matplolib极坐标图x轴标签位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用(可能是滥用?)极性图表来表示一些数据。我想要将当前位于x轴上方的标签置于数据段上方。



我已经找到了多篇关于如何旋转所有东西的文章,但它总是将标签保持在轴的正上方。



代码的平衡我有轴(如果你需要整个定义/代码,请这样说):

 #设置轴名称和方向
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 ],angle = 22)

它产生的当前图像:



>



现在我想要标签'Seg 1''Seg 2'

解决方案



/ div>

您可以通过在次要标记上设置标签,但将次要标记宽度设置为零,以便您看不到它们:

 
import matplotlib.ticker as ticker

#设置主要和次要刻度位置
ax.xaxis.set_major_locator(ticker.MultipleLocator(np.pi / 4))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(np.pi / 8))

#关闭主刻度线标签
ax.xaxis.set_major_formatter(ticker.NullFormatter() )

#将小的刻度宽度设置为0,使您不会看到它们
在ax.xaxis.get_minor_ticks()中的刻度:
tick.tick1line.set_markersize(0 )
tick.tick2line.set_markersize(0)
tick.label1.set_horizo​​ntalalignment('center')

#设置刻度的名称,
ax.set_xticklabels(['','','Seg 1','','Seg 2','','Seg 3','','Seg 4' ','','Seg 6','','Seg 7','','Seg 8'],minor = True)


I'm using (maybe misusing?) a Polar chart to represent some data I have. I would like to have the labels, currently positioned right above the x-axis, to be above the segment of data. So right between the axis.

I've found multiple articles on how to rotate everything but it always keeps the label right above the axis.

The peace of code I have for the axis (if you need the whole definition/code, please say so):

# 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)

The current image it produces:

Now I'd like the labels 'Seg 1', 'Seg 2', etc. to be moved from the axis to right between the axis.

Is there any way to do that?

解决方案

you can do this by setting the labels on minor ticks, but then setting the minor tick width to zero so you don't see them:

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)

这篇关于python matplolib极坐标图x轴标签位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆