日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3绘图_python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)

發布時間:2025/3/8 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3绘图_python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#!/usr/bin/env python# -*- coding:utf-8 -*-from matplotlib import pyplot as pltimport numpy as npimport pylabimport os,sys,time,math,random# 圖1-給已有的圖加上刻度file=r‘D:\jmeter\jmeter3.2\data\Oracle數據庫基礎.png‘arr=np.array(file.getdata()).reshape(file.size[1],file.size[0],3)plt.gray()plt.imshow(arr)plt.colorbar()plt.show()# 圖2-隨機柱狀圖SAMPLE_SIZE=100random.seed()real_rand_vars=[]real_rand_vars=[random.random() for val in range(SAMPLE_SIZE)]pylab.hist(real_rand_vars,10)pylab.xlabel("number range")pylab.ylabel("count")pylab.show()# 圖3-正太分布圖duration=100# 中值mean_inc=0.6# 標準差std_dev_inc=1.2x=range(duration)y=[]price_today=0for i in x: next_delta=random.normalvariate(mean_inc,std_dev_inc) price_today+=next_delta y.append(price_today)pylab.plot(x,y)pylab.title(‘test‘)pylab.xlabel(‘time‘)pylab.ylabel(‘value‘)pylab.show()# 圖4SAMPLE_SIZE=1000buckes=100plt.figure()plt.rcParams.update({‘font.size‘:7})# 子圖1-隨機分布 0~1plt.subplot(621)plt.xlabel(‘random1‘)res=[random.random() for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖2-均勻分布plt.subplot(622)plt.xlabel(‘random2‘)a=1b=SAMPLE_SIZEres=[random.uniform(a,b) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖3-三角形分布plt.subplot(623)plt.xlabel(‘random3‘)low=1high=SAMPLE_SIZEres=[random.triangular(a,b) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖4-beta分布圖plt.subplot(624)plt.xlabel(‘random4‘)alpha=1beta=10res = [random.betavariate(alpha,beta) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖5-指數分布圖plt.subplot(625)plt.xlabel(‘random5‘)lambd=1.0/((SAMPLE_SIZE+1)/2)res=[random.expovariate(lambd) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖6-gamma分布圖plt.subplot(626)plt.xlabel(‘random6‘)alpha=1beta=10res = [random.gammavariate(alpha,beta) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖7-對數正太分布圖plt.subplot(627)plt.xlabel(‘random7‘)# 中值mu=1# 標準差sigma=0.5res = [random.lognormvariate(mu,sigma) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖8-正太分布圖plt.subplot(628)plt.xlabel(‘random8‘)# 中值mu=1# 標準差sigma=0.5res = [random.normalvariate(mu,sigma) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)# 子圖9-帕累托分布圖plt.subplot(629)plt.xlabel(‘random9‘)# 形狀參數alpha=1res = [random.paretovariate(alpha) for _ in range(1,SAMPLE_SIZE)]plt.hist(res,buckes)plt.tight_layout()plt.show()

總結

以上是生活随笔為你收集整理的python3绘图_python3绘图示例2(基于matplotlib:柱状图、分布图、三角图等)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。