I'm having a problem with matplotlib. I'm using the linux Chrome OS distro. When I try to creat a graph, it doesn't show me anything, just this: Graph
This is the script:
import matplotlib.pyplot as plt
x = [10,20,30,40,50,60]
bin = [10]
plt.hist(x,bin)
plt.show()
My IDE is Vim
This happened because you supplied the wrong argument to plt.hist
. According to the documentation:
bins : int or sequence or str, default: :rc:`hist.bins`
If *bins* is an integer, it defines the number of equal-width bins
in the range.
If *bins* is a sequence, it defines the bin edges, including the
left edge of the first bin and the right edge of the last bin;
in this case, bins may be unequally spaced. All but the last
(righthand-most) bin is half-open. In other words, if *bins* is::
[1, 2, 3, 4]
then the first bin is ``[1, 2)`` (including 1, but excluding 2) and
the second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which
*includes* 4.
If *bins* is a string, it is one of the binning strategies
supported by `numpy.histogram_bin_edges`: 'auto', 'fd', 'doane',
'scott', 'stone', 'rice', 'sturges', or 'sqrt'.
So by supplying [10]
, you haven't supplied the end of a bin, only the start, and nothing is generated. You can fix this with plt.hist(x,10)
or plt.hist(x, [10, 20, 30 <rest>])
.
In addition, try to avoid overwriting builtin functions like bin
. It won't affect you now, but might haunt you later.