【问题标题】:Offset matplotlib `ticklabels` from axis [duplicate]从轴偏移matplotlib`ticklabels`[重复]
【发布时间】:2016-09-28 10:17:12
【问题描述】:

在使用polar=True 的一些(相当小的)图形中,ticklabels 与轴重叠。例如:

import numpy as np
import matplotlib.pylab as pl

fig = pl.figure(figsize=[2,2])
fig.subplots_adjust(0.2, 0.2, 0.8, 0.8)
ax = pl.subplot(111, polar=True)
ax.set_yticks([])

创建:

是否可以在轴和标签之间设置偏移量,即将180 向左移动一点,0 向右移动,等等?我更喜欢按subplot 设置它,因为我在同一个图中还有一些其他subplots 不需要ticklabel 偏移量。

【问题讨论】:

标签: python matplotlib


【解决方案1】:

您正在寻找PolarAxes 类的set_thetagrids 方法,除了允许您定义theta 坐标网格的属性之外,还可以通过缩放frac 来设置刻度标签的径向偏移量争论。有关更多信息,请参阅docs。这是相同字体和图形大小的修改示例:

import numpy as np
import matplotlib.pylab as pl

fig = pl.figure(figsize=[2,2])
fig.subplots_adjust(0.2, 0.2, 0.8, 0.8)
ax = pl.subplot(111, polar=True)

# if you want to preserve the old tick degrees
old_ticks = ax.xaxis.get_ticklocs() / np.pi * 180
ax.set_thetagrids(old_ticks, frac=1.3)
ax.set_yticks([])
pl.show()

编辑:@nostradamus 在 OP 评论部分链接的 answer 比我自己的更详细。我建议你看看它。

【讨论】:

  • 是的,我同意,没有看到那个问题,它完美地回答了我的问题。
猜你喜欢
  • 2017-07-31
  • 1970-01-01
  • 2012-09-01
  • 1970-01-01
  • 2014-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
相关资源
最近更新 更多