小编sha*_*olf的帖子

如何在pyplot中自动注释最大值?

我试图找出如何自动注释图窗口中的最大值.我知道你可以通过手动输入x,y坐标以使用.annotate()方法注释你想要的任何点来做到这一点,但我希望注释是自动的,或者自己找到最大点.

到目前为止,这是我的代码:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pandas import Series, DataFrame

df = pd.read_csv('macrodata.csv') #Read csv file into dataframe
years = df['year'] #Get years column
infl = df['infl'] #Get inflation rate column

fig10 = plt.figure()
win = fig10.add_subplot(1,1,1)
fig10 = plt.plot(years, infl, lw = 2)

fig10 = plt.xlabel("Years")
fig10 = plt.ylabel("Inflation")
fig10 = plt.title("Inflation with Annotations")
Run Code Online (Sandbox Code Playgroud)

这是它生成的数字

python numpy matplotlib pandas

6
推荐指数
3
解决办法
3万
查看次数

标签 统计

matplotlib ×1

numpy ×1

pandas ×1

python ×1