python3繪圖示例4(基於matplotlib:箱線圖、散點圖等)
阿新 • • 發佈:2018-12-16
scatter 繪圖 utf-8 show pre otto 2個 figure plot
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from matplotlib.pyplot import *
x=[1,2,3,4]
y=[5,4,3,2]
# 創建新圖標
figure()
# 對角線圖 第1個參數:2行 第2個參數:3列的網格 第3個參數:圖形在網格的位置
subplot(231)
plot(x,y)
# 垂直柱狀圖
subplot(232)
bar(x,y)
# 水平柱狀圖
subplot(233)
barh(x,y)
# 堆疊柱狀圖-顏色間隔
subplot(234)
bar(x,y)
y1=[7,8,5,3]
bar(x,y1,bottom=y,color=‘r‘)
# 箱線圖
subplot(235)
boxplot(x)
# 散點圖
subplot(236)
scatter(x,y)
show()
# 箱線圖-柱狀圖
dataset=[113,115,119,121,124,124,125,126,126,127,127,128,129,130,130,131,132,133,136]
subplot(121)
boxplot(dataset,vert=False)
subplot(122)
hist(dataset)
show()
python3繪圖示例4(基於matplotlib:箱線圖、散點圖等)