1 回答
TA贡献1951条经验 获得超3个赞
只需添加plt.xticks(rotation=45)到脚本的末尾就可以了。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
base = datetime.datetime.today()
date_list = [base - datetime.timedelta(days=x) for x in range(40)]
df = pd.DataFrame(data = {
"Time": date_list,
"Chocolate": np.random.rand(40),
"Strawberry": np.random.rand(40),
"Fake Chocolate": np.random.rand(40),
"Fake Strawberry": np.random.rand(40),
})
df.iloc[3,3] = np.nan
ax1 = df.plot(x = 'Time', y = ["Chocolate","Strawberry"])
ax1 = df.plot(x = 'Time', y = ["Chocolate","Strawberry"])
ax2 = df.plot.scatter(x = 'Time', y = ['Fake Chocolate'], marker = '^', ax = ax1)
ax3 = df.plot.scatter(x = 'Time', y = ['Fake Strawberry'], marker = '*', ax = ax1, color = '#ff7f0e')
plt.xticks(rotation=45);
添加回答
举报