一个问题是 x 轴间距。 Excel 图表中的间距与数字之间的差异不成比例;它不是线性的或对数的。因此,您可以根据整数绘制 y 值,然后在之后重命名 ticks。见here:
import matplotlib.pyplot as plt
plt.figure(figsize=(7,2))
x_coordinates = [1000, 10000, 100000,250000,500000,1000000]
x_positions = range(len(x_coordinates)) # get int positions
y1_coordinates = [0.016, 0.096, 0.9893,2.9166,9.2952,21.779]
y2_coordinates = [0.13, 15.215, 557.45,4768.842,55577.73,77777]
# plot against integers
plt.xlabel('number of elements(n)')
plt.plot(x_positions, y1_coordinates)
plt.ylabel('time in secs')
plt.plot(x_positions, y2_coordinates)
# relable with coordinates
plt.xticks(ticks=x_positions, labels=x_coordinates)
橙色曲线在 x=500000 时看起来仍然不同;但这似乎只是绘制的数据略有不同。
您也可以通过将x_coordinates 转换为字符串来实现类似的效果:
# this makes the same graph as above
import matplotlib.pyplot as plt
plt.figure(figsize=(7,2)) # for size
x_coordinates = [1000, 10000, 100000,250000,500000,1000000]
x_coordinates = [str(i) for i in x_coordinates]
y1_coordinates = [0.016, 0.096, 0.9893,2.9166,9.2952,21.779]
y2_coordinates = [0.13, 15.215, 557.45,4768.842,55577.73,77777]
# plot against integers
plt.xlabel('number of elements(n)')
plt.plot(x_coordinates, y1_coordinates)
plt.ylabel('time in secs')
plt.plot(x_coordinates, y2_coordinates)
x轴下方有表格的东西比较独特;我不确定在matplotlib 中是否有一种简单的方法可以轻松实现这一点。如果这更多是您感兴趣的部分,您可以编辑您的问题/创建一个新问题(但 see this post 或 this example)。