使用 matplotlib 和 pandas 库绘图不清楚

2023-11-30

enter image description here

有什么解释为什么我会得到这样的情节吗?指数回报的范围是从 100 到 130。我需要帮助来理解上面的这个图。代码很简单,但是情节不太清晰:

#import needed library
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#import JPM GBI bound index
df = pd.read_excel('art.xlsx')
df = pd.DataFrame(df) 
df.head(8)

plt.plot(df\['Date'\],df\['Index returns'\])
type(df\['Date'\]\[3\])

Matplotlib 按照提供的顺序绘制数据。如果需要,您可以对数据进行排序。

import numpy as np
import matplotlib.pyplot as plt

x = np.array([3, 5, 1, 2, 7, 4, 6, 9, 8])
y = np.array([8, 10, 3, 6, 8, 10, 10, 3, 6])

plt.subplot(121)
plt.plot(x,y, marker="o", label="unsorted")

plt.legend()

# now sort the values
plt.subplot(122)
plt.plot(np.sort(x),y[np.argsort(x)], marker="o", color="C3", label="sorted")

plt.legend()
plt.show()

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 matplotlib 和 pandas 库绘图不清楚 的相关文章

随机推荐