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

Jus*_*tin 4 python matplotlib typeerror bar-chart

我意识到之前已经问过这个问题(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,我也会收到错误.在此先感谢您的帮助

wfl*_*nny 7

你确定这是你的所有代码吗?代码在哪里抛出错误?在策划期间?因为这适合我:

In [16]: import numpy as np
In [17]: x = np.arange(1,8, 1)
In [18]: y = np.exp(x)

In [20]: import matplotlib.pyplot as plt
In [21]: fig = plt.figure()
In [22]: ax = fig.add_subplot(111)
In [24]: ax.bar(x, y, log=1)
Out[24]: 
[<matplotlib.patches.Rectangle object at 0x3cb1550>,
 <matplotlib.patches.Rectangle object at 0x40598d0>,
 <matplotlib.patches.Rectangle object at 0x4059d10>,
 <matplotlib.patches.Rectangle object at 0x40681d0>,
 <matplotlib.patches.Rectangle object at 0x4068650>,
 <matplotlib.patches.Rectangle object at 0x4068ad0>,
 <matplotlib.patches.Rectangle object at 0x4068f50>]
In [25]: plt.show()
Run Code Online (Sandbox Code Playgroud)

这是情节 在此输入图像描述