【问题标题】:python matplolib polar chart x-axis label positionpython matplotlib极坐标图x轴标签位置
【发布时间】:2014-03-13 20:33:51
【问题描述】:

我正在使用(可能是滥用?)极坐标图来表示我拥有的一些数据。我希望当前位于 x 轴正上方的标签位于数据段的上方。所以就在轴之间。

我找到了多篇关于如何旋转所有内容的文章,但它始终将标签保持在轴的正上方。

我对轴的代码和平(如果您需要完整的定义/代码,请说出来):

# 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' 等从轴向右移动到轴之间。

有什么办法吗?

【问题讨论】:

    标签: python charts matplotlib axis-labels placement


    【解决方案1】:

    您可以通过在次要刻度上设置标签来做到这一点,然后将次要刻度宽度设置为零,这样您就看不到它们了:

    导入 matplotlib.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 5','' ,'Seg 6','','Seg 7','','Seg 8'],minor=True)

    【讨论】:

    • 谢谢!它立即在我自己的计算机上运行。但是,当我在远程站点上尝试它时,它没有。没有错误,但标签只是没有移动。在更新 matplotlib 之后,它就像一个魅力。所以这似乎只在以后的版本中有效?还是我真的有旧版本?
    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多