作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法增加极坐标图刻度标签(θ)的填充/偏移?
import matplotlib
import numpy as np
from matplotlib.pyplot import figure, show, grid
# make a square figure
fig = figure(figsize=(2, 2))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
ax.set_yticklabels([])
r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.0)
show()
最佳答案
首先;看看您如何指定 figsize
为 (2,2) 并具有 ax
占据宽度和高度的 80%,你几乎没有剩余的空间来填充刻度标签。这可能会导致刻度标签在图形的边界处被“切断”。这可以很容易地被“修复”
figsize
ax
在 (2,2) 大小的图上占用更少的空间 Axes
的界限;
ax = fig.add_subplot(111, polar=True, axisbg='#d5de9c')
因为这样可以使用方法
tight_layout()
它会自动配置图形布局以很好地包含所有元素。
PolarAxes
除其他外,您可以设置 theta-ticks 的径向位置。这是通过指定要放置刻度标签的极轴半径的分数作为
frac
的参数来完成的。
PolarAxes
的参数的
set_thetagrids()
方法。参数应该是要放置刻度标签的轴半径的一小部分。即为
frac
< 1 刻度标签将放置在轴内,而对于
frac
> 1 它们将被放置在轴外。
import numpy as np
from matplotlib.pyplot import figure, show, grid, tight_layout
# make a square figure
fig = figure(figsize=(2, 2))
ax = fig.add_subplot(111, polar=True, axisbg='#d5de9c')
ax.set_yticklabels([])
r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.0)
# tick locations
thetaticks = np.arange(0,360,45)
# set ticklabels location at 1.3 times the axes' radius
ax.set_thetagrids(thetaticks, frac=1.3)
tight_layout()
show()
frac
尝试不同的值找到最适合您需求的值。
frac
指定值如上,即
frac
有默认值
None
,代码输出如下图。注意绘图的半径是如何变大的,因为刻度标签不像上面的例子那样“占据尽可能多的空间”。
关于matplotlib:向极坐标图刻度标签添加填充/偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17159668/
我正在寻找绘制极坐标数据的替代方法。我需要实现像 this 这样的图表具有动态选项,例如 this . 非常感谢您的帮助! 最佳答案 我个人需要这些: Highcharts JS canvasXpre
我是一名优秀的程序员,十分优秀!