极坐标图旁边的垂直轴

时间:2017-08-02 10:06:28

标签: python matplotlib plot axis

任何人都可以指导我如何使用matplotlib将垂直轴放在极坐标图旁边?

http://www.originlab.com/doc/Origin-Help/Polar-Graph引用所需结果的示例。

如图所示,左边是我的极坐标图中所需的垂直条,我想在matplotlib中重现: enter image description here

编辑:这是我想要将垂直轴添加到的代码示例。

import matplotlib.pyplot as plt
import numpy as np

def sin_func(array):
    final = np.array([])
    for value in array:
        final = np.append(final, abs(np.sin(value)))
    return final

x = np.arange(0, 4*np.pi, 0.1)
y = sin_func(x)

fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')

plt.plot(x, y)
# Changing axis to pi scale
ax.set_ylim([0, 1.2])
x_tick = np.arange(0, 2, 0.25)
x_label = [r"$" + format(r, '.2g') + r"\pi$" for r in x_tick]
ax.set_xticks(x_tick*np.pi)
ax.set_xticklabels(x_label, fontsize=10)
ax.set_rlabel_position(110)

plt.show()

enter image description here

1 个答案:

答案 0 :(得分:3)

在您需要的位置添加add_axes方法的附加轴,然后根据需要设置刻度位置和标签:

echo "export DEVKITPRO=/opt/devkitPro" >> ~/.bashrc

enter image description here