matplot完成多表操作

在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()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值