I have a lot different pandas.Series looks like:
my_series:
0.0 10490405.0
1.0 3334931.0
2.0 2770406.0
3.0 2286555.0
4.0 1998229.0
5.0 1636747.0
6.0 1449938.0
7.0 1180900.0
8.0 1054964.0
9.0 869783.0
10.0 773747.0
11.0 653608.0
12.0 595688.0
...
682603.0 1.0
734265.0 1.0
783295.0 1.0
868135.0 1.0
This is the frequincies of my data: this mean there are 10490405 zeros in my data, 3334931 of 1 and etc. I want to plot histogram.
I know I can do it using plt.bar
:
plt.bar(my_series.index, my_series.values)
But It works bad because of large number of unique values in my_series
(it can be thousand!). So bars at the plot too narrow and became invizible!
So I really want to use hist
to set manually number of bins and etc.
But I can't use my_series.hist() because it has not such number of zeros it has just one value for zero label!
code to reproduce the problem:
val = np.round([1000000/el**2 for el in range(1,1000)])
ind = [el*10+np.random.randint(10) for el in range(1,1000)]
my_series = pd.Series(val, ind)
plt.bar(my_series.index, my_series.values)
As I already has close vote and wrong answer I got my problem description is really bad. I want to add the example:
val1 = [100, 50, 25, 10, 10, 10]
ind1 = [0, 1, 2, 3, 4, 5]
my_series1 = pd.Series(val1, ind1)
my_series.hist()
This is just hist() on series values! So we can see, that 10 has value 3 (because there are three of them in the series) and all other has value 1 on the hist. What I want to get:
0 label has value 100, 1 label has value 50 and so on.
myseries.hist()
andmyseries.hist(bins=your_bins)
?plt.bar
toplt.fill_between(my_series.index, 0, my_series.values)
. In your case it works well because there's barely any difference between that and simply plt.plot :)