Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีแสดง Logarithmic Plot ของ Cumulative Distribution Function ใน Matplotlib

ในการแสดง Logarithmic plot ของ cumulative distribution function ใน Matplotlib เราสามารถทำตามขั้นตอนต่อไปนี้:

ขั้นตอน

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • เริ่มต้นตัวแปร N สำหรับจำนวนข้อมูลตัวอย่าง
  • สร้างข้อมูล X2 และ F2 ด้วย numpy
  • พลอต X2 และ F2 ด้วยเมธอด plot()
  • ทำให้แกน x และ y เป็น logarithmic scale
  • เพื่อแสดงรูป ใช้เมธอด show()

ตัวอย่าง

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

N = 100
data = np.random.randn(N)
X2 = np.sort(data)
F2 = np.array(range(N)) / float(N)

plt.plot(X2, F2)
plt.xscale('log')
plt.yscale('log')
plt.show()

ผลลัพธ์

วิธีแสดง Logarithmic Plot ของ Cumulative Distribution Function ใน Matplotlibวิธีแสดง Logarithmic Plot ของ Cumulative Distribution Function ใน Matplotlib