如何阻止我的图形的标签出现在图形中?

2024-09-30 22:24:36 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这句话给我添麻烦了:

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

根据文献记载,“frac是极轴半径的一部分 放置标签(1是边缘)。e、 g.轴外为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()

Tags: 函数labelsplotstatsnppipltax
1条回答
网友
1楼 · 发布于 2024-09-30 22:24:36

看看What's new in matplotlib 2.1上面写着:

[...] Additionally, tick labels now obey the padding settings that previously only worked on Cartesian plots. Consequently, the frac argument to PolarAxes.set_thetagrids is no longer applied. Tick padding can be modified with the pad argument to Axes.tick_params or Axis.set_tick_params.

相关问题 更多 >