在Matplotlib中按照名稱繪製比例尺類別線性和對數、邏輯和對數對稱?


要按照名稱繪製帶有類別的yscale,我們可以按以下步驟操作:

  • 設定圖形大小並調整子圖的內外邊距。
  • 使用Numpy建立y資料點。
  • 使用Numpy建立x資料點。
  • 在索引1處向當前影像新增子圖。
  • 使用plot()方法繪製x和y資料點。
  • 對於按名稱分級的線性類,使用yscale("linear")方法。
  • 設定當前子圖的標題。從4到5步驟重複上述操作,使用不同的索引、按名稱分級的yscale()和繪圖示題。
  • 要顯示影像,請使用show()方法。

示例

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))

# linear
plt.subplot(221)
plt.plot(x, y)
plt.yscale('linear')
plt.title('linear')

# log
plt.subplot(222)
plt.plot(x, y)
plt.yscale('log')
plt.title('log')

# symmetric log
plt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale('symlog', linthreshy=0.01)
plt.title('symlog')

# logit
plt.subplot(224)
plt.plot(x, y)
plt.yscale('logit')
plt.title('logit')
plt.show()

輸出

更新日期:2021年6月2日

448 次檢視

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.