如何在 matplotlib 2.0 中僅使用陰影填充區域(無背景顏色)?
要在 matplotlib 中使用僅陰影(無背景顏色)填充一個區域,我們可以採取以下步驟 -
步驟
設定圖形大小並調整子圖之間和周圍的邊距。
初始化變數 n 以儲存樣本資料的數量。
建立一個圖形和一組子圖。
繪製 x 和 y 資料點。
使用圓形陰影填充 x 和 y 之間的區域,edgecolor="blue"。
要顯示圖形,請使用 show() 方法。
示例
import numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Number of sample data n = 256 # x and y data points x = np.linspace(-np.pi, np.pi, n, endpoint=True) y = np.sin(2 * x) # Figure and set of subplots fig, ax = plt.subplots() # Plot the data points ax.plot(x, y, color='blue', alpha=1.0) # Fill the area between the data points ax.fill_between(x, y, color='blue', alpha=.2, facecolor="none", hatch="o", edgecolor="blue", linewidth=1.0) # Display the plot plt.show()
輸出
它將產生以下輸出 -

廣告
資料結構
網路
資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP