簡體   English   中英

Python-使用matplotlib繪制對數圖

[英]Python - Plot a log-log plot with matplotlib

我只想在對數-對數比例圖中繪制“ a vs b ”,但出現錯誤。

import matplotlib.pyplot as plt

a = [7255.151855, 231.589661, 9.365415, 0.55364, 1.5001, 0.006408, 0.001204, 0.000842]
b = [0.212399, 0.393191, 0.727874, 1.347436, 2.494368, 4.617561, 8.548006, 15.824027]

CyclesPerBlock = 219397
LoadAmplitude = 4990

a = [x*CyclesPerBlock for x in a]
b = [y*LoadAmplitude for y in b]

fig = plt.plot
fig.set_xscale("log")
fig.set_yscale("log")
fig.set_xlim(1e-3, 1e4)
fig.set_ylim(1e-1, 1e3)
fig.set_aspect(1)
fig.set_title("Calculation Results")

fig.plot(a, b, "o-")
plt.draw()
plt.show()

您必須先創建AxesSubplot對象,然后使用它來繪制:

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_xlim(1e-3, 1e4) # <-- check this as pointed out by @tillsten
ax.set_ylim(1e-1, 1e3) # <--
ax.set_aspect(1)
ax.set_title("Calculation Results")

ax.plot(a, b, "o-")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM