網站首頁 編程語言 正文
什么是Matplotlib?
Matplotlib是Python中的一個庫,用于創建靜態和動態動畫,并使用其內置函數繪制。它有很多內置特性和內置分析工具,用于分析任何圖形或圖表。
如果我們想繪制任何三維圖形,那么我們可以使用Matplotlib庫。當我們有一個巨大的三維變量數據集,我們繪制它的圖形時,它看起來非常分散,這被稱為3D散點圖。我們將使用Matplotlib的matplot3d工具包繪制三維圖形。
有一把斧頭。函數,它接受坐標X、Y和Z的數據集。
根據我們想要賦予三維圖的屬性,需要更多的論證。
首次創建Matplotlib時,只考慮二維繪圖。大約在1.0版本發布時,通過在Matplotlib的二維顯示器上分層一些三維圖表工具,創建了一個實用的(盡管相當有限)三維數據可視化工具集。通過導入mplot3d工具包(它是基本Matplotlib安裝的一部分),三維圖表成為可能。
最簡單的三維圖是由(x,y,z)三元組的線或簇組成的散點圖。這些可以用斧頭生產。plot3D和ax。scatter3D函數,很像之前呈現的更典型的二維圖表。它們的呼叫特征與二維對應物非常相似。
為了在頁面上創建深度錯覺,散射點的透明度已經改變。
示例1:
# importing the necessary libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# generating random dataset
z = np.random.randint(80, size =(55))
x = np.random.randint(60, size =(55))
y = np.random.randint(64, size =(55))
# Creating figures for the plot
fig = plt.figure(figsize = (10, 7))
ax = plt.axes(projection ="3d")
# Creating a plot using the random datasets
ax.scatter3D(x, y, z, color = "red")
plt.title("3D scatter plot")
# display the plot
plt.show()
輸出:
解釋:
在上面的示例中,我們使用ax創建了三維繪圖。scatter()函數。我們最初已經導入了所需的所有庫,如numpy、matplotlib和mpl_toolkits。然后,我們使用randInt()函數創建了隨機數的x、y和z坐標的數據集。在那之后,我們使用了斧頭。scatter3D()函數,并輸入x、y和z坐標,我們為點取紅色。最后,我們使用show()函數顯示繪圖。
示例2:
# importing the necessary libraries
from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt
import numpy as np
# Creating random dataset
z = 4 * np.tan(np.random.randint(10, size =(500))) + np.random.randint(100, size =(500))
x = 4 * np.cos(z) + np.random.normal(size = 500)
y = 4 * np.sin(z) + 4 * np.random.normal(size = 500)
# Creating figure
fig = plt.figure(figsize = (16, 12))
ax = plt.axes(projection ="3d")
# Add x, and y gridlines for the figure
ax.grid(b = True, color ='blue',linestyle ='-.', linewidth = 0.5,alpha = 0.3)
# Creating the color map for the plot
my_cmap = plt.get_cmap('hsv')
# Creating the 3D plot
sctt = ax.scatter3D(x, y, z,alpha = 0.8,c = (x + y + z),cmap = my_cmap,marker ='^')
plt.title("3D scatter plot in Python")
ax.set_xlabel('X-axis', fontweight ='bold')
ax.set_ylabel('Y-axis', fontweight ='bold')
ax.set_zlabel('Z-axis', fontweight ='bold')
fig.colorbar(sctt, ax = ax, shrink = 0.6, aspect = 5)
# display the plot
plt.show()
輸出:
解釋:
在上面的代碼中,我們用函數ax繪制了三維圖。scatter3D()函數。我們生成了x、y和z坐標的隨機數據集,并使用標記“^”繪制了它們。我們使用set_label函數為各個軸提供標簽。
原文鏈接:https://blog.csdn.net/std7879/article/details/127804598
相關推薦
- 2022-12-15 QT中對話框的使用示例詳解_C 語言
- 2022-05-11 兩分鐘完成創建virtualbox創建k8s集群詳解
- 2022-04-12 C#實現六大設計原則之里氏替換原則_C#教程
- 2022-09-12 Python詳解復雜CSV文件處理方法_python
- 2022-10-06 詳解hive常見表結構_數據庫其它
- 2023-07-16 uniapp 小程序訂閱消息報錯( wx.requestSubscribeMessage is no
- 2022-08-21 golang協程與線程區別簡要介紹_Golang
- 2022-06-22 Android使用EventBus多次接收消息_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同步修改后的遠程分支