網站首頁 編程語言 正文
為了找到matplotlib在兩個點之間連線的方法真是費了好大功夫,本文主要介紹了?matplotlib繪制兩點間連線的幾種方法,具體如下
繪制方法 <1>
本文將通過最簡單的模式拆解Matplotlib繪圖的幾個組成部分,將cover以下內容
1. Create a dataset
2. Create a canvas
3. Add data to canvas
4. Show the figure
import numpy as np import matplotlib.pyplot as plt # create a dataset points = np.linspace(-5, 5, 256) y1 = np.tanh(points) + 0.5 y2 = np.sin(points) - 0.2 # create a canvas fig, axe = plt.subplots(figsize=(7, 3.5), dpi=300) # add data to canvas axe.plot(points, y1) axe.plot(points, y2) # show the figure fig.savefig('output/to.png') plt.close(fig)
繪制方法<2> 使用pyplot繪制圖像
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) plt.plot(x, y)
繪制方法<3> 使用axes類繪制圖像
使用axes使用subplot()繪制單一圖像,使用subplots(nrows,ncols
)繪制多個圖形
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) ax = plt.subplot() ax.plot(x, y)
繪制方法<4> 使用figure類繪制圖像
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) fig = plt.figure(dpi=300) ax = fig.add_subplot(111) ax.plot(x, y) fig.savefig('output/to.png') plt.close(fig)
表示了圖像的position。如果使用subplots,則有nrows
,ncols
, andindex
三個參數,其中idex從1開始,代表了左上角的圖像
原文鏈接:https://blog.csdn.net/weixin_33918358/article/details/112486438
相關推薦
- 2022-10-26 Python?NumPy教程之二元計算詳解_python
- 2022-09-21 詳解C語言中typedef和#define的用法與區別_C 語言
- 2022-06-28 使用?Docker?Compose?構建復雜的多容器?App的方法_docker
- 2023-01-11 Android?nonTransitiveRClass資源沖突問題淺析_Android
- 2022-05-23 Python?圖形界面框架TkInter之在源碼中找pack方法_python
- 2022-05-29 C#調用USB攝像頭的方法_C#教程
- 2022-01-22 oracle之連接查詢和子查詢
- 2022-03-30 Android中圖片占用內存的深入分析_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支