画出成交量线图、柱状图、箱线图、饼图 import warnings warnings.filterwarnings("ignore", message="Support for FigureCanvases without a required_interactive_framework attribute was deprecated in Matplotlib 3.6 and will be removed two minor releases later.") warnings.filterwar
时间: 2024-03-31 12:37:19 浏览: 175
nings("ignore", message="Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.")
import matplotlib.pyplot as plt
import numpy as np
# 生成数据
x = np.arange(1, 11)
y = np.array([5, 7, 6, 8, 9, 7, 6, 4, 8, 5])
volume = np.array([100, 120, 90, 80, 150, 200, 160, 100, 110, 130])
data = [np.random.normal(0, std, 100) for std in range(1, 4)]
# 成交量线图
fig, ax = plt.subplots()
ax.plot(x, y)
ax2 = ax.twinx()
ax2.fill_between(x, volume, 0, alpha=0.2, color='blue')
plt.title('成交量线图')
plt.show()
# 柱状图
fig, ax = plt.subplots()
ax.bar(x, y)
plt.title('柱状图')
plt.show()
# 箱线图
fig, ax = plt.subplots()
ax.boxplot(data)
plt.title('箱线图')
plt.show()
# 饼图
fig, ax = plt.subplots()
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
ax.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.title('饼图')
plt.show()
阅读全文