Python Matplotlib庫(kù)實(shí)現(xiàn)畫(huà)局部圖
在畫(huà)圖中,我們需要放大圖像的某一部分,看清其變化。最近在寫(xiě)論文時(shí),就遇到了這個(gè)問(wèn)題,還有坐標(biāo)軸加粗、控制線(xiàn)型和大小等要求。這些,都可以通過(guò)Python Matplotlib庫(kù)實(shí)現(xiàn)。具體看下面的代碼:
import matplotlib.pyplot as plt init_np = np.array(x0_list) xopt_net_np = np.array(xopt_net) plt.figure(figsize=(8,5)) plt.subplot(311) ax = plt.gca() # 獲取坐標(biāo)軸 bwith = 1.2 ax.spines['bottom'].set_linewidth(bwith) ax.spines['left'].set_linewidth(bwith) ax.spines['top'].set_linewidth(bwith) ax.spines['right'].set_linewidth(bwith) plt.yticks([]) plt.xlim([-21,21]) plt.plot(init_np, np.zeros_like(init_np), '.b', markersize=2, label='initial value Distri.') plt.legend() plt.subplot(312) ax = plt.gca() bwith = 1.2 ax.spines['bottom'].set_linewidth(bwith) ax.spines['left'].set_linewidth(bwith) ax.spines['top'].set_linewidth(bwith) ax.spines['right'].set_linewidth(bwith) plt.yticks([]) plt.xlabel('x') plt.plot(xopt_gd, np.zeros_like(xopt_gd), '.r', markersize=2, label='optimal value Distri. by GD') plt.xlim([-21,21]) plt.legend() plt.subplot(313) ax = plt.gca() bwith = 1.2 ax.spines['bottom'].set_linewidth(bwith) ax.spines['left'].set_linewidth(bwith) ax.spines['top'].set_linewidth(bwith) ax.spines['right'].set_linewidth(bwith) plt.yticks([]) plt.plot(xopt_net_np, np.zeros_like(xopt_net_np), '.r', markersize=2, label='optimal value Distri. by Network') plt.xlim([-21,21]) plt.legend() plt.axes([0.125,0.275,0.25,0.07]) # list:[左下角水平坐標(biāo), 左下角垂直坐標(biāo), 寬度, 高度] # plt.xticks(()) plt.yticks(()) plt.plot(xopt_net_np, np.zeros_like(xopt_net_np), '.r', markersize=1, label='optimal value Distr.') plt.savefig('sol_scipy_ai.png', dpi=400, bbox_inches='tight') plt.show()
得到了下面的效果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
利用Python實(shí)現(xiàn)數(shù)值積分的方法
這篇文章主要介紹了利用Python實(shí)現(xiàn)數(shù)值積分。本文主要用于對(duì)比使用Python來(lái)實(shí)現(xiàn)數(shù)學(xué)中積分的幾種計(jì)算方式,并和真值進(jìn)行對(duì)比,加深大家對(duì)積分運(yùn)算實(shí)現(xiàn)方式的理解2022-02-02Django中使用haystack+whoosh實(shí)現(xiàn)搜索功能
這篇文章主要介紹了Django之使用haystack+whoosh實(shí)現(xiàn)搜索功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10利用Python和C++實(shí)現(xiàn)解析gltf文件
gltf是類(lèi)似于stl、obj、ply等常見(jiàn)的3D對(duì)象存儲(chǔ)格式,它被設(shè)計(jì)出來(lái)是為了便于渲染的數(shù)據(jù)轉(zhuǎn)換和傳輸,本文為大家介紹了使用Python和C++解析gltf文件的方法,感興趣的可以了解下2023-09-09Python+OpenCV圖像處理之直方圖統(tǒng)計(jì)
直方圖就是對(duì)圖像的另外一種解釋?zhuān)枋隽苏鶊D像的灰度分布。通過(guò)直方圖我們可以對(duì)圖像的亮度、灰度分布、對(duì)比度等有了一個(gè)直觀(guān)的認(rèn)識(shí)。本文將為大家詳細(xì)介紹一下如何通過(guò)OpenCV實(shí)現(xiàn)直方圖統(tǒng)計(jì),感興趣的可以了解一下2021-12-12python測(cè)試攻略pytest.main()隱藏利器實(shí)例探究
在Pytest測(cè)試框架中,pytest.main()是一個(gè)重要的功能,用于啟動(dòng)測(cè)試執(zhí)行,它允許以不同方式運(yùn)行測(cè)試,傳遞參數(shù)和配置選項(xiàng),本文將深入探討pytest.main()的核心功能,提供豐富的示例代碼和更全面的內(nèi)容,2024-01-01Python使用itchat模塊實(shí)現(xiàn)群聊轉(zhuǎn)發(fā),自動(dòng)回復(fù)功能示例
這篇文章主要介紹了Python使用itchat模塊實(shí)現(xiàn)群聊轉(zhuǎn)發(fā),自動(dòng)回復(fù)功能,結(jié)合實(shí)例形式分析了Python基于itchat模塊針對(duì)微信信息的發(fā)送、回復(fù)等相關(guān)操作技巧,需要的朋友可以參考下2019-08-08python計(jì)算最大優(yōu)先級(jí)隊(duì)列實(shí)例
python計(jì)算最大優(yōu)先級(jí)隊(duì)列實(shí)例,大家參考使用吧2013-12-12