Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barplot with log y-axis program syntax with matplotlib pyplot

I realize that this question has been asked before(Python Pyplot Bar Plot bars disappear when using log scale), but the answer given did not work for me. I set my pyplot.bar(x_values, y_values, etc, log = True) but got an error that says:

"TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'"

I have been searching in vain for an actual example of pyplot code that uses a bar plot with the y-axis set to log but haven't found it. What am I doing wrong?

here is the code:

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()

I get an error even when I removre pyplot.show. Thanks in advance for the help

like image 864
physics_researcher Avatar asked Dec 16 '22 07:12

physics_researcher


1 Answers

Are you sure that is all your code does? Where does the code throw the error? During plotting? Because this works for me:

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()

Here's the plot enter image description here

like image 138
wflynny Avatar answered Dec 27 '22 06:12

wflynny