我一直在尝试使用pypthon中的matplotlib绘制极坐标图但有一些问题。而不是正常的0-360度,我想把时间,0-23小时和半径将是纬度,即从90-0(极点到赤道)。
我试图在matplotlib投影polar.py
示例中更改一些设置,但结果并没有不同。这就是我得到的:
答案 0 :(得分:1)
如果您小心,可以考虑反转纬度并手动更改两个轴上的刻度标签。
以下是如何实现这一目标的示例,更多解释为评论:
$app->cache->put($requestCache . '_Minute', 0, 1); // value 0, expire in 1 minute
$app->cache->increment($requestCache . '_Minute'); // doing this resets the 1 minute expire time
您的结果将如下所示(请记住随机数据会有所不同):
要确定它确实有效,您可以使用以下行替换随机import numpy as np
from matplotlib import pyplot as plt
# set up random data between 0 and 90
r = [np.random.random() * 90.0 for i in range(0,10)]
# set up 24 hours matching the random data above
hours = np.linspace(0.0,24.0,len(r))
# scaling the 24 hours to the full circle, 2pi
theta = hours / 24.0 * (2.0 * np.pi)
# reverse your data, so that 90 becomes 0:
r_rev = [(ri - 90.0) * -1.0 for ri in r]
# set up your polar plot
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r_rev, color='r', linewidth=3)
# define your axis limits
ax.set_ylim([0.0, 90.0])
# statically reverse your y-tick-labels
# caution: this turns your labels into strings
# and decouples them from the data
#
# the np.linspace gives you a distribution between 90 and 0 -
# the number of increments are related to the number of ticks
# however, you require one more label, because the center is
# omitted.
ax.set_yticklabels(['{:.0f}'.format(ylabel) \
for ylabel in np.linspace(90.0,0.0,len(ax.get_yticklabels())+1)[1:]])
# statically turn your x-tick-labels into fractions of 24
# caution: this turns your labels into strings
# and decouples them from the data
#
# the number of ticks around the polar plot is used to derive
# the appropriate increment for the 24 hours
ax.set_xticklabels(['{:.1f}'.format(xlabel) \
for xlabel in np.arange(0.0,24.0,(24.0 / len(ax.get_xticklabels())))])
ax.grid(True)
plt.show()
:
r
现在你知道了r = np.linspace(0,90,10)
- 值,并且可以看到它们是如何被翻转的。