我需要使用 Matplotlib 绘制一个 loglog 直方图(bot x 和 y 以 log10 比例),但以下代码没有显示我想要的输出:
import matplotlib.pyplot as plt
import numpy as np
fig, ax1 = plt.subplots()
# suppose to have an array x
ax1.hist(x, ec='white', color="red")
plt.xscale("log")
plt.yscale("log")
plt.show()
我想要的输出是一个直方图,其中 x=np.log10(x) 和等效 y=np.log10(y),其中 y 中的每个元素是每个 bin 的高度。我什至尝试使用条形图,但我无法解决重叠箱的问题:
import matplotlib.pyplot as plt
import numpy as np
frequency_dict = Counter(x)
new_x = list(frequency_dict.keys())
y = list(frequency_dict.values())
ax1.bar(np.log10(new_x), np.log10(y), ec='white', color="red")
plt.show()