我正在尝试将温度函数与特定体积绘制成图表,但该函数是如此倾斜,以至于我无法制作出我想要的数字。
import matplotlib.pyplot as plt
import numpy as np
x = [0.00100034, 0.00100184, 0.00100441, 0.00100789, 0.00101027, 14.67, 14.867, 15.335, 15.801]
y = [10, 20, 30, 40, 45.806, 45.806, 50, 60, 70]
plt.plot(x, y)
plt.show()
这不是我想要的,因为它看起来像 x 是恒定的,因为 y 在 x 值较小时增加,但我希望它是倾斜的,并表明 y 随着 x 值较小时 x 增加而增加。
我尝试使用以下代码来使用日志:
import matplotlib.pyplot as plt
import numpy as np
x = [0.00100034, 0.00100184, 0.00100441, 0.00100789, 0.00101027, 14.67, 14.867, 15.335, 15.801]
y = [10, 20, 30, 40, 45.806, 45.806, 50, 60, 70]
plt.xscale('log')
plt.plot(x, y)
plt.show()
但它导致数字是
更糟糕的是,不仅之前的问题仍然存在,而且随着 y 值的增加,x 看起来也保持不变。
然后我尝试使用代码来使用断点
from brokenaxes import brokenaxes
import matplotlib.pyplot as plt
import numpy as np
y = [10, 20, 30, 40, 45.806, 45.806, 50, 60, 70]
x = [0.00100034, 0.00100184, 0.00100441, 0.00100789, 0.00101027, 14.67, 14.867, 15.335, 15.801]
bax = brokenaxes(xlims=((.001, .002), (14, 16)))
plt.plot(x, y)
plt.show()
但这也不能解决问题,因为它会导致数字
很明显,对于较小的 x 值以及非常大的 x 值,y 随着 x 的增加而增加,并且需要在两端倾斜
我见过很多 stackoverflow 问题,并多次询问 chatgpt 但我无法得到答案
如果您不介意间隙,您可以在两个并排的轴上绘制数据:
import matplotlib.pyplot as plt
import numpy as np
x = [0.00100034, 0.00100184, 0.00100441, 0.00100789, 0.00101027, 14.67, 14.867, 15.335, 15.801]
y = [10, 20, 30, 40, 45.806, 45.806, 50, 60, 70]
fig, (ax_low, ax_high) = plt.subplots(ncols=2, sharey=True, layout='constrained', width_ratios=[1, 2])
# Plot two parts of the data with the (x[4], y[4]) in both sets.
ax_low.plot(x[:5], y[:5])
ax_high.plot(x[4:], y[4:])
# Remove inside and top spines and ticks.
ax_low.spines.right.set_visible(False)
ax_low.spines.top.set_visible(False)
ax_high.spines.left.set_visible(False)
ax_high.spines.top.set_visible(False)
ax_high.tick_params(axis='y', left=False)
# Set the inside xlim to the common x data point.
ax_low.set_xlim(right=x[4])
ax_high.set_xlim(left=x[4])
# Rotate the long x-labels so we can distinguish them
ax_low.tick_params(axis='x', labelrotation=30)
plt.show()