如何使用 Matplotlib 更改繪圖的面部顏色?
要使用 matplotlib 更改繪圖的面部顏色,我們可以採取以下步驟:-
- 設定圖形大小並調整各子圖之間和周圍的內邊距。
- 使用 numpy 建立 x 和 y 資料點。
- 建立一個圖形和一組子圖。
- 使用 color=yellow 和 linewidth=7 的 plot() 方法繪製 x 和 y 資料點。
- 使用 set_facecolor() 設定座標軸的面部顏色。
- 要顯示圖形,請使用 show() 方法。
範例
from matplotlib import pyplot as plt
import numpy as np
# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
# Create x and y data points
x = np.linspace(-10, 10, 100)
y = np.sin(x)
# Create a figure and set of subplots
fig, ax = plt.subplots()
# Plot the x and y data points with color
ax.plot(x, y, color='yellow', lw=7)
# Set the facecolor
ax.set_facecolor('red')
plt.show()輸出
它將生成以下輸出


廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C #
MongoDB
MySQL
Javascript
PHP