代码求指教

绘图代码如下
def plot_percentage(data,file_name):
    # 对数据进行排序
    sorted_data = np.sort(data)

    # 计算小于每个值的百分比
    percentages = np.arange(1, len(sorted_data) + 1) / len(sorted_data)

    # 绘制曲线图
    plt.figure(figsize=(20, 6))
    plt.plot(sorted_data, percentages)
    plt.xlabel('t (seconds)')
    plt.ylabel('Percentage')
    plt.title('Percentage of Values Less Than t')
    plt.xticks([1, 2, 4, 8, 30, 60, 120, 1800, 3600],
               ['1s', '2s', '4s', '8s', '30s', '1m', '2m', '30m', '1h'],rotation=45)
    
    plt.xlim(0, 4000)
    #for x, y in zip(sorted_data, percentages):
        #plt.annotate(f'{y:.2%}', (x, y), textcoords="offset points", xytext=(0,10), ha='center')
    plt.savefig(file_name+'.png')
    plt.show()
横坐标时间,纵坐标百分比
想要实现的图1的
但是代码实现是图2,求帮助
全部评论
横坐标不要用数字,换成字符串
点赞 回复
分享
发布于 03-13 18:00 吉林

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务