python - 如何使用 matplotlib 修复注释问题
问题描述
我目前正在尝试在 的每个标记位置下绘制两个线图以及注释ylabel
。但是,我面临一个问题,即仅绘制第一个而不是在其位置。
这是我的代码:
import matplotlib.pyplot as plt
ax = plt.subplot(111)
first =[0.9122,0.9091,0.9073,0.898,0.888,0.8855,0.8831,0.8837,0.8815,0.8612,0.8628,0.8419,0.8022,0.7805,0.7414]
second=[0.9499,0.9472,0.9421,0.938,0.9401,0.94,0.9417,0.9387,0.9398,0.9395,0.9263,0.9115,0.9089,0.9050,0.8893]
x = [10,20,30,40,50,60,70,80,90,100,200,400,600,800,1000]
xi = [i for i in range(0, len(x))]
plt.xticks(xi, x)
ax.plot(xi, first, marker='x')
ax.plot(xi, second, marker='^')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
ax.legend(loc='upper center',
bbox_to_anchor=(0.5, # horizontal
1.12),# vertical
ncol=3, fancybox=True)
for x, y in zip(x, first):
label = y * 100
ax.annotate(label, # this is the text
(x, y), # this is the point to label
textcoords="offset points", # how to position the text
xytext=(0, 0), # distance from text to points (x,y)
ha='center')
plt.show()
解决方案
推荐阅读
- c++ - 在自定义容器上使用范围算法
- node.js - 无法在 Electron 中加载预加载脚本,但绝对路径正确
- linux - 如何允许应用声明“https”方案 URI?(即如何从 https URL 打开桌面应用程序?)
- node.js - 在节点 js 中每隔 10、20、30、40、50、60 分钟运行一次 cron 作业
- c# - C# Entity Framework Core .NET5.0 单元测试挂起的迁移
- c# - 如何将 JSON 数组解析为字符串?
- sql - sql:累计和(按日期按客户顺序分区)
- swagger - Swagger UI 的 CORS 问题
- javascript - 在 onchange 事件中传递 html 中的 javascript 对象
- android - 如何确定 android 应用程序是否使用可信执行环境 (TEE) 和安全元件 (SE)?