相关疑难解决方法(0)

python中的对数y轴箱

我正在尝试创建数据列的直方图并以对数方式绘制(y-axis)并且我不确定为什么以下代码不起作用:

import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('foo.bar')
fig = plt.figure()
ax = fig.add_subplot(111)
plt.hist(data, bins=(23.0, 23.5,24.0,24.5,25.0,25.5,26.0,26.5,27.0,27.5,28.0))
ax.set_xlim(23.5, 28)
ax.set_ylim(0, 30)
ax.grid(True)
plt.yscale('log')
plt.show()
Run Code Online (Sandbox Code Playgroud)

我也试过,而不是plt.yscale('log')添加Log=trueplt.hist行,我也尝试过ax.set_yscale('log'),但似乎没有任何工作.我得到一个空图,要么y-axis是对数(代码如上所示),但没有绘制数据(没有箱子).

python logarithm matplotlib histogram

40
推荐指数
2
解决办法
6万
查看次数

Barplot与日志y轴程序语法与matplotlib pyplot

我意识到之前已经问过这个问题(Python Pyplot Bar Plot bars在使用log scale时消失了),但给出的答案对我来说不起作用.我设置了我的pyplot.bar(x_values,y_values等,log = True)但是出现了一个错误:

"TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'"
Run Code Online (Sandbox Code Playgroud)

我一直在寻找一个pyplot代码的实际例子,该代码使用条形图,y轴设置为log但尚未找到它.我究竟做错了什么?

这是代码:

import matplotlib.pyplot as pyplot
ax = fig.add_subplot(111)
fig = pyplot.figure()
x_axis = [0, 1, 2, 3, 4, 5]
y_axis = [334, 350, 385, 40000.0, 167000.0, 1590000.0]
ax.bar(x_axis, y_axis, log = 1)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)

即使我删除了pyplot.show,我也会收到错误.在此先感谢您的帮助

python matplotlib typeerror bar-chart

4
推荐指数
1
解决办法
5857
查看次数

标签 统计

matplotlib ×2

python ×2

bar-chart ×1

histogram ×1

logarithm ×1

typeerror ×1