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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

画图设置刻度_总结了16个常用的matlibplot画图技巧(附源码)

發布時間:2024/9/19 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 画图设置刻度_总结了16个常用的matlibplot画图技巧(附源码) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

↑↑↑關注后"星標"簡說Python

人人都可以簡單入門Python、爬蟲、數據分析

簡說Python推薦

來源:python數據分析之禪?作者:小dull鳥

One?old?watch,?like?brief python

大家好,我是老表~

今天給大家分享16個用matlibplot畫圖的常用技巧,也是我經常記不住的,廢話不多說,直接上干貨。

1.添加文本框

為文本添加添加背景框

import?matplotlib.pyplot?as?plt
plt.rcParams['font.sans-serif']?=?['SimHei']
fig=plt.figure()
fig,axe=plt.subplots()
axe.text(0.5,0.5,'我是文本框',bbox={'facecolor':'cyan','alpha':0.5,'pad':0.7})??#添加文本框
plt.show()


2.添加指示箭頭

import?matplotlib.pyplot?as?plt
import?numpy?as?np
plt.rcParams['axes.unicode_minus']?=?False
fig=plt.figure()
fig,axe=plt.subplots()
t=np.arange(0.0,2.0,0.01)
s=np.sin(2*np.pi*t)
axe.plot(t,s,linestyle='-',label='line1')
axe.annotate('我是正弦函數',xy=(1.25,1),xytext=(1.9,1),
??????????????????arrowprops=dict(facecolor='red',shrink=0.2),
?????????????????horizontalalignment='center',verticalalignment='center')
plt.show()

3.改變折線形狀

fig,axe=plt.subplots()
np.random.seed(100)
x=np.arange(0,?10,?1)
y1=np.random.rand(10)
axe.plot(x,?y1,?'--o')
plt.show()

4.柱狀圖橫置

fig,axe=plt.subplots()
data_m=(40,?60,?120,?180,?20,?200)
index?=?np.arange(6)
width=0.4
axe.barh(index,?data_m,?width,align='center',alpha=0.8,?label='men')
plt.show()

5.移動坐標軸位置

import?matplotlib.pyplot?as?plt
import?numpy?as?np
fig=plt.figure()
fig,axe=plt.subplots()
axe.spines['right'].set_color('none')
axe.spines['top'].set_color('none')
axe.spines['bottom'].set_position(('data',1))
axe.spines['left'].set_position(('data',1))
plt.show()


6.設置坐標軸范圍

fig=plt.figure()
fig,axe=plt.subplots()
plt.xlim(0,10)
plt.ylim(0,8000)
plt.show()


7.改變坐標軸顏色

import?matplotlib.pyplot?as?plt
import?numpy?as?np
fig=plt.figure()
fig,axe=plt.subplots()
axe.spines['right'].set_color('yellow')
axe.spines['top'].set_color('red')
plt.show()


8.設置坐標軸刻度

fig=plt.figure()
fig,axe=plt.subplots()
axe.set_xticks([0,1,2,3,4,5])
plt.show()


9.改變刻度

fig=plt.figure()
fig,axe=plt.subplots()
axe.set_xticks([0,1,2,3,4,5])
axe.set_xticklabels(['Taxi','Metro','Walk','Bus','Bicycle','Driving'])
plt.show()


9.坐標傾斜

fig=plt.figure()
fig,axe=plt.subplots()
axe.set_xticks([0,1,2,3,4,5])
axe.set_xticklabels(['Taxi','Metro','Walk','Bus','Bicycle','Driving'],rotation=45)
plt.show()


10.繪制子圖

fig=plt.figure()
fig,axe=plt.subplots(4,4,figsize=(10,10))
plt.show()


11.加網格線

fig=plt.figure()
fig,axe=plt.subplots()
axe.grid(True)
plt.show()


12.改變圖形顏色

fig,axe=plt.subplots()
data_m=(40,?60,?120,?180,?20,?200)
index?=?np.arange(6)
axe.bar(index,?data_m,color='y')
plt.show()

13.改變樣式

fig,axe=plt.subplots()
data_m=(40,?60,?120,?180,?20,?200)
index?=?np.arange(6)
axe.bar(index,?data_m)
plt.style.use('dark_background')
plt.show()

樣式列表:

plt.style.available
['bmh',
'classic',
'dark_background',
'fast',
'fivethirtyeight',
'ggplot',
'grayscale',
'seaborn-bright',
'seaborn-colorblind',
'seaborn-dark-palette',
'seaborn-dark',
'seaborn-darkgrid',
'seaborn-deep',
'seaborn-muted',
'seaborn-notebook',
'seaborn-paper',
'seaborn-pastel',
'seaborn-poster',
'seaborn-talk',
'seaborn-ticks',
'seaborn-white',
'seaborn-whitegrid',
'seaborn',
'Solarize_Light2',
'tableau-colorblind10',
'_classic_test']

14.添加表格

fig,axe=plt.subplots()
data_m=(40,?60,?120,?180,?20,?200)
data_f=(30,?100,?150,?30,?20,?50)
index?=?np.arange(6)
width=0.4
#bar?charts
axe.bar(index,?data_m,?width,?color='c',?label='men')
axe.bar(index,?data_f,?width,?color='b',?bottom=data_m,?label='women')
axe.set_xticks([])
axe.legend()
#table
data=(data_m,data_f)
rows=('male','female')
columns=('Taxi','Metro','Walk','Bus','Bicycle','Driving')
axe.table(cellText=data,?rowLabels=rows,?colLabels=columns)
plt.show()

15.餅狀圖分離

fig,?axe?=?plt.subplots()
labels?=?'Taxi',?'Metro',?'Walk',?'Bus','Bicycle','Drive'
sizes?=?[10,?30,?5,?25,?5,?25]
explode?=?(0.1,?0.1,?0.5,?0.1,?0.1,?0.1)???#控制分隔距離
axe.pie(sizes,?explode=explode,?labels=labels,?autopct='%1.1f%%',
????????shadow=True,?startangle=90)
axe.axis('equal')
plt.show()

16.保存繪制的圖片

fig,?axe?=?plt.subplots()
labels?=?'Taxi',?'Metro',?'Walk',?'Bus','Bicycle','Drive'
sizes?=?[10,?30,?5,?25,?5,?25]
explode?=?(0.1,?0.1,?0.5,?0.1,?0.1,?0.1)???#控制分隔距離
axe.pie(sizes,?explode=explode,?labels=labels,?autopct='%1.1f%%',
????????shadow=True,?startangle=90)
axe.axis('equal')
plt.savefig('temp.png',?dpi=fig.dpi)

可以關注公眾號簡說Java,后臺回復關鍵字“matlibplot”獲取完整源碼。

長按掃碼回復【matlibplot

簡說Python

長按掃碼關注,一起學Python

學習更多:整理了我開始分享學習筆記到現在超過250篇優質文章,涵蓋數據分析、爬蟲、機器學習等方面,別再說不知道該從哪開始,實戰哪里找了

總結

以上是生活随笔為你收集整理的画图设置刻度_总结了16个常用的matlibplot画图技巧(附源码)的全部內容,希望文章能夠幫你解決所遇到的問題。

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