Python 資料科學 - Matplotlib



什麼是 Matplotlib?

Matplotlib 是一個 Python 庫,用於使用 Python 指令碼建立 2D 圖表和繪圖。它有一個名為 pyplot 的模組,透過提供控制線型、字型屬性、格式化軸等功能,使繪圖變得更容易。它支援各種各樣的圖表和繪圖,例如直方圖、條形圖、功率譜、誤差圖等。它與 NumPy 一起使用,提供了一個有效開源的 MatLab 替代環境。它還可以與 PyQt 和 wxPython 等圖形工具包一起使用。

通常,透過新增以下語句將包匯入 Python 指令碼中:

from matplotlib import pyplot as plt

Matplotlib 示例

以下指令碼使用 matplotlib 生成**正弦波圖**。

示例

import numpy as np 
import matplotlib.pyplot as plt  

# Compute the x and y coordinates for points on a sine curve 
x = np.arange(0, 3 * np.pi, 0.1) 
y = np.sin(x) 
plt.title("sine wave form") 

# Plot the points using matplotlib 
plt.plot(x, y) 
plt.show() 

其**輸出**如下:

Sine Wave

在接下來的章節中,我們將看到許多關於在資料科學工作中使用 Python 的 Matplotlib 庫的示例。

廣告

© . All rights reserved.