欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

python-matplotlib繪圖總結(面對函數和面對對象繪圖技巧)

系統 1918 0

環境 : matplotlib 3.1.0,? numpy 1.15.4

目錄

使用matplotlib作圖的兩大方法

一 面對函數繪圖(pyplot模塊有大量函數,供用戶調用)

1.?主要分為四個步驟:

2. 代碼實例(單圖和多圖)

3. 圖片展示

二 面對對象繪圖(主要操作Figure和Axes對象)(推薦)

1.?主要分為四個步驟:

2. 代碼實例(單圖和多圖)

3. 圖片展示


使用matplotlib作圖的兩大方法

本教程可以作為科研作圖模板, 涵蓋了作圖中很多小細節, 使用了matplotlib作圖的常用函數和對象

一 面對函數繪圖(pyplot模塊有大量函數,供用戶調用)

functions大都是從matlab移植過來的,熟悉matlab繪圖的讀者能夠很快入門?

1.?主要分為四個步驟:

(1) 準備數據和創建畫布; (2) 繪制線條、散點圖; (3) 對線條、散點圖、坐標軸進行描述;(4) 顯示畫布。

2. 代碼實例(單圖和多圖)

            
              import numpy as np
import matplotlib.pyplot as plt

# 1. 準備數據
np.random.seed(19680801)
N, fonts = 50, 8

x1 = np.linspace(0, 2*np.pi, num=1000)
y1, yy1 = 0.2*np.sin(x1*10) + 0.75, 0.15*np.sin(x1*10+0.2) + 0.25
x2, y2 = np.random.rand(N), np.random.rand(N)

# 創建畫布
plt.figure(figsize=(6, 4), dpi=300)

# 2.繪制線條、散點圖
plt.plot(x1, y1, color='r', linewidth=2, label="line 1")
plt.plot(x1, yy1, color='g', linewidth=2, label="line 2")
plt.scatter(x2, y2, s=8, c='b', label="scatter", marker='*')
# 3. 對線條、散點圖、坐標軸進行描述
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('xlable', fontsize=fonts)
plt.ylabel('ylabel', fontsize=fonts)
xticklabels = np.arange(0, 1.2, 0.2)
yticklabels = np.arange(0, 1.2, 0.2)
plt.xticks(ticks=xticklabels, labels=[str(round(xx, 1)) for xx in xticklabels])
plt.yticks(ticks=yticklabels, labels=[str(round(xx, 1)) for xx in yticklabels])
plt.title("figure 1", fontsize=fonts)
plt.legend(loc='upper left', fontsize=fonts)
plt.grid(True)
plt.tight_layout(pad=0.3)

# 4. 顯示并保存畫布
plt.savefig("./1.tiff")
plt.show()

##############################################################################################################
# 1.準備數據( 參上)
# 創建畫布
plt.figure(figsize=(6, 3), dpi=300)

# 2.對線條、散點圖、坐標軸進行描述
# 繪制第一個子圖
plt.subplot(121)
plt.plot(x1, y1, color='r', linewidth=2, label="line 1")
plt.plot(x1, yy1, color='g', linewidth=2, label="line 2")
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('xlable', fontsize=fonts)
plt.ylabel('ylabel', fontsize=fonts)
plt.title("figure 2", fontsize=fonts)
plt.legend(loc='upper left', fontsize=fonts)
plt.grid(True)
plt.tight_layout(pad=0.3)

# 繪制第二個子圖
plt.subplot(122)
plt.scatter(x2, y2, s=8, c='b', label="scatter", marker='*')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('xlable', fontsize=fonts)
plt.ylabel('ylabel', fontsize=fonts)
plt.title("figure 3", fontsize=fonts)
plt.legend(loc='upper left', fontsize=fonts)
plt.grid(True)
plt.tight_layout(pad=0.3)

# 4. 顯示并保存畫布
plt.savefig("./2.tiff")
plt.show()
            
          

3. 圖片展示

python-matplotlib繪圖總結(面對函數和面對對象繪圖技巧)_第1張圖片 python-matplotlib繪圖總結(面對函數和面對對象繪圖技巧)_第2張圖片

二 面對對象繪圖(主要操作Figure和Axes對象)(推薦)

理解了matplotliblib包里面的Figure和Axes對象, 繪制漂亮的科研圖就能夠運用自如、得心應手

1.?主要分為四個步驟:

(1) 準備數據;(2) 創建Figure和Axes對象;(3) 進行線條、散點圖、坐標軸繪制和描述;(4) 顯示畫布。

2. 代碼實例(單圖和多圖)

            
              import numpy as np
import matplotlib.pyplot as plt

# 1. 準備數據
np.random.seed(19680801)
N, fonts = 50, 8
x1 = np.linspace(0, 2*np.pi, num=1000)
y1 = 0.2*np.sin(x1*10) + 0.75
yy1 = 0.15*np.sin(x1*10+0.2) + 0.25
x2, y2 = np.random.rand(N), np.random.rand(N)

# 2. 創建一個Figure對象和一個Axes對象
fig, ax = plt.subplots(figsize=(6, 4), dpi=300)

# 3 進行線條、散點圖、坐標軸繪制和描述
ax.plot(x1, y1, color='g', linewidth=2, label="line 1")
ax.plot(x1, yy1, color='r', linewidth=2, label="line 2")
ax.scatter(x2, y2, s=8, c='b', label="scatter", marker='*')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_xlabel('xlable', fontsize=fonts)
ax.set_ylabel('ylabel', fontsize=fonts)
xticklabels = np.arange(0, 1.2, 0.2)
yticklabels = np.arange(0, 1.2, 0.2)
ax.set_xticks(xticklabels)
ax.set_yticks(yticklabels)
ax.set_xticklabels(labels=[str(round(xx, 1)) for xx in xticklabels], fontdict={'fontsize': fonts})
ax.set_yticklabels(labels=[str(round(xx, 1)) for xx in yticklabels], fontdict={'fontsize': fonts})
ax.set_title("figure 4", fontsize=fonts)
ax.legend(loc='upper left', fontsize=fonts)
ax.grid(True)

fig.tight_layout(pad=0.3)
fig.savefig("./3.tiff")

# 4.顯示畫布
plt.show()
###############################################################################
# 1.準備數據(參上)

# 2.創建一個Figure對象和兩個Axes對象
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(6, 3), dpi=300)

# 3.對軸描述
# 對軸一描述
ax[0].plot(x1, y1, color='g', linewidth=2, label="line 1")
ax[0].plot(x1, yy1, color='r', linewidth=2, label="line 2")
ax[0].set_xlim(0, 1)
ax[0].set_ylim(0, 1)
ax[0].set_xlabel('xlable', fontsize=fonts)
ax[0].set_ylabel('ylabel', fontsize=fonts)
ax[0].set_title("figure 2", fontsize=fonts)
ax[0].legend(loc='upper left', fontsize=fonts)
ax[0].set_title("figure 5", fontsize=fonts)
ax[0].grid(True)

# 對軸二描述
ax[1].scatter(x2, y2, s=8, c='b', label="scatter", marker='*')
ax[1].set_xlim(0, 1)
ax[1].set_ylim(0, 1)
ax[1].set_xlabel('xlable', fontsize=fonts)
ax[1].set_ylabel('ylabel', fontsize=fonts)
ax[1].set_title("figure 3", fontsize=fonts)
ax[1].legend(loc='upper left', fontsize=fonts)
ax[1].set_title("figure 6", fontsize=fonts)
ax[1].grid(True)

fig.tight_layout(pad=0.3)
fig.savefig("./4.tiff")
# 4.顯示畫布
plt.show()
            
          

3. 圖片展示

python-matplotlib繪圖總結(面對函數和面對對象繪圖技巧)_第3張圖片

python-matplotlib繪圖總結(面對函數和面對對象繪圖技巧)_第4張圖片

?

?

?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 婷婷天天 | 麻豆av电影在线观看 | 91精品国产色综合久久 | 一级片视频网站 | 91在线中文 | 韩漫重考生漫画画免费读漫画下拉式土豪漫 | 免费成人福利视频 | 国产一区二区三区日韩欧美 | 欧美日韩视频在线第一区 | 国产在线视频一区二区 | 日韩中文字幕视频在线 | 免费午夜视频 | 色七七网站 | 深夜日韩 | 欧美久久久久久 | 男女www视频| 九九热免费视频在线观看 | 亚洲免费在线 | 亚洲视频 在线观看 | 成人亚洲一区 | 大陆黄色网 | 精品乱子伦一区二区三区 | 午夜精品久久久久久久久久久久久 | 亚洲区第一页 | 天天摸夜夜摸夜夜狠狠摸 | 久久天堂网 | 91p在线 | 青青草娱乐在线 | 亚洲欧美精品综合中文字幕 | 99久久久久久 | 国内精品久久久久影院老司 | www.国产一区| 午夜视频在线免费观看 | 亚洲成av | 欧美午夜精品久久久久免费视 | 二级黄绝大片中国免费视频 | 日本一区二区三区免费观看 | 久久夜夜操妹子 | 久久国产视频网站 | 久久久婷婷一区二区三区不卡 | 亚洲欧美日韩另类精品一区二区三区 |