如何阻止图表的标签进入图表内?

问题描述 投票:0回答:1

我创建了一个函数来生成蜘蛛/雷达图但我遇到了错误。

这条线给我带来了麻烦:

ax.set_thetagrids(angles * 180/np.pi, labels = labels, color='blue', frac=1.5)

根据文档,“frac是放置标签的极轴半径的一部分(1是边缘)。例如,1.05在轴外,0.95在轴内。”

但是,即使我设置frac = 1.5,标签仍然与绘图本身重叠。 This is an example of a plot

=========================================================================

这是整个函数定义:

import matplotlib.pyplot as plt
import numpy as np

def make_radar_chart(name, stats, labels, plot_markers = markers, plot_str_markers = str_markers):
    markers = [1,2, 3, 4, 5, 6, 7, 8, 9, 10]
    str_markers = ["",'', "", '', "", '', "", "", "", '']
    labels = np.array(labels)

    angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
    stats = np.concatenate((stats,[stats[0]]))
    angles = np.concatenate((angles,[angles[0]]))

    fig= plt.figure()
    ax = fig.add_subplot(111, polar=True)
    ax.plot(angles, stats, 'green', linewidth=1)
    ax.fill(angles, stats, 'green', alpha=0.25)
    ax.set_thetagrids(angles * 180/np.pi, labels = labels, color='blue', frac=1.5)
    plt.yticks(markers)
    plt.yticks([1,2,3,4,5,6,7,8,9], ["",'','3','',"5","",'7','',''], color="grey", size=7)
    ax.set_title(name)
    ax.grid(True)
    return plt.show()
python python-2.7 numpy matplotlib
1个回答
0
投票

查看What's new in matplotlib 2.1所在的位置:

[...]此外,刻度标签现在遵循以前仅适用于笛卡尔图的填充设置。因此,fracPolarAxes.set_thetagrids论证不再适用。可以使用padAxes.tick_paramsAxis.set_tick_params参数修改tick填充。

© www.soinside.com 2019 - 2024. All rights reserved.