matplotlib 如何从一组pandas格式的元组绘制一个图?

cgh8pdjw  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(93)

...

print (data)
    close_prices = data[1]
    dates = data.index 

    fig, ax = plt.subplots()
    ax.plot(dates, close_prices)
    ax.set_xticklabels(dates, rotation=45)
    ax.set_title(f"Daily Close Prices for IBM")
    ax.set_xlabel("Date")
    ax.set_ylabel("Price ($)")

    plt.tight_layout()
    plt.show()

...
数据是从AlphVantage API调用的,我以pandas格式输出它。如何在图表上只显示收盘价?

xmjla07d

xmjla07d1#

import pandas as pd
import matplotlib.pyplot as plt

data = [(1, 3), (2, 5), (3, 4), (4, 6), (5, 8)]
df = pd.DataFrame(data, columns=['x', 'y'])

df.plot(x='x', y='y', kind='line')
plt.show()

相关问题