在Python中 使用matplot 模块完成多表操作
代码如下
``
import matplotlib.pyplot as plt
import numpy as np
1.线图
figure
figure = plt.figure()
subplot = figure.add_subplot(2, 2, 1)
subplot.plot(np.arange(0, 100), np.arange(1, 101))
2.柱状图
subplot2 = figure.add_subplot(2, 2, 2)
data = np.array(((556316.546, 1, ‘python’), (456426.564, 2, ‘java’), (264285.23, 3, ‘C#’)))
data = data.T
xlabel = data[2]
x = data[1].astype(np.float)
y = data[0].astype(np.float)
bars = subplot2.bar(x, y, width=0.3)
subplot2.set_ylabel(“salary/month”)
subplot2.set_xlabel(“positon”)
subplot2.set_xticks(x)
subplot2.set_xticklabels(xlabel)
subplot2.grid(linestyle=’–’)
颜色设置
i = 0
for bar in bars:
bar.set_color(’#’ + str(111111+i))
i += 420212
pass
for x, y in zip(x, y):
subplot2.text(x, y + 0.05, ‘{0}$/month’.format(np.float(y)), ha=‘center’, va=‘bottom’)
pass
3.饼图
subplot3 = figure.add_subplot(2, 2, 3)
data = np.arange(1, 6)/np.sum(np.arange(1, 6))
print(data)
labels = [‘A{0}%’.format(x ** 100) for x in data]
subplot3.pie(data, colors=[’#009966’, ‘#006699’, ‘#FF0000’, ‘#00FF00’, ‘#0000FF’], labels=labels)
4.点图
subplot4 = figure.add_subplot(2, 2, 4)
x = np.random.randint(1, 100, 100)
y = np.random.randint(1, 100, 100)
subplot4.scatter(x, y, s=30, c=x, alpha=0.8, marker=’*’)
plt.show()