เพื่อให้เห็นภาพค่าในระดับลอการิทึมบน matplotlib เราสามารถใช้ yscale('log') .
ขั้นตอน
-
นำเข้า matplotlib nd numpy
-
กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย
-
สร้าง x และ ย จุดข้อมูลโดยใช้ numpy
-
ใช้ yscale('log') เพื่อให้เห็นภาพค่าในระดับลอการิทึม
-
พล็อต x และ ย จุดข้อมูลโดยใช้ พล็อต วิธีการ
-
วางตำนานบนร่าง
-
หากต้องการแสดงรูป ให้ใช้ show() วิธีการ
ตัวอย่าง
import numpy as np
from matplotlib import pyplot as plt
# Set the figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
# x and y data points
x = np.linspace(1, 100, 1000)
y = np.log(x)
# logarithmic scale
plt.yscale('log')
# Plot the x and y data points
plt.plot(x, y, c="red", lw=3, linestyle="dashdot", label="y=log(x)")
# Place the legend
plt.legend()
# Display the plot
plt.show() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้ -
