在这里插入代码片
``
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
import pandas as pd
import matplotlib.pyplot as plt
example = {'Timestamp':
['2021-10', '2021-11', '2021-12', '2022-01', '2022-02', '2022-03',
'2022-04', '2022-05', '2022-06', '2022-07', '2022-08','2022-09','2022-10'],
'数':
[7,178, 437, 280, 204,249,844,475,468,264,490,822,561]}
df = pd.DataFrame(example)```
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
sns.set_style("whitegrid")
x = df['Timestamp']
y =df['数']
plt.rcParams['figure.figsize'] = (12.0,5.0)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.bar(x,y,alpha=.7,color='g')
ax1.set_ylabel('数',fontsize='15')
ax2 = ax1.twinx()
ax2.set_ylabel('',fontsize='15')
ax2.plot(x, y, 'r',ms=10)
plt.show()
有标数据
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
import pandas as pd
import matplotlib.pyplot as plt
example = {'Timestamp':
['2021-10', '2021-11', '2021-12', '2022-01', '2022-02', '2022-03',
'2022-04', '2022-05', '2022-06', '2022-07', '2022-08','2022-09','2022-10'],
'数':
[7,178, 437, 280, 204,249,844,475,468,264,490,822,561]}
df = pd.DataFrame(example)
x = df['Timestamp']
y =df['弹幕数']
plt.bar(x=x, height=y, label='', color='steelblue', alpha=0.8)
for x1, yy in zip(x, y):
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=10, rotation=0)
plt.title("弹幕数随日期活跃度")
plt.xlabel("发布日期")
plt.ylabel("数量")
plt.legend()
plt.plot(x, y, "r", marker='*', ms=10, label="a")
plt.xticks(rotation=45)
plt.legend(loc="upper left")
plt.savefig("a.jpg")
plt.show()