Python-使用matplotlib绘制日志图

Python-使用matplotlib绘制日志图,python,matplotlib,plot,logarithm,Python,Matplotlib,Plot,Logarithm,我只想在一个对数缩放图中绘制“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] CyclesPerB

我只想在一个对数缩放图中绘制“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-")
fig=plt.figure()
ax=图添加_子批次(111)
ax.setxscale(“日志”)
ax.设置刻度(“对数”)

ax.set_xlim(1e-3,1e4)#您必须首先创建
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-")
fig=plt.figure()
ax=图添加_子批次(111)
ax.setxscale(“日志”)
ax.设置刻度(“对数”)

ax.set_xlim(1e-3,1e4)#你得到了答案,但在发布问题时最好包含完整的回溯。发布生成问题所需的最低代码量也是最好的。您已经得到了答案,但在发布问题时最好包含完整的回溯。最好发布生成问题所需的最低代码量。