1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Histogram in Python

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of numbers.The list is like [0,0,1,0,1 .... ] .Presently it has binary digits only but later on it can have decimal digits as well. I want to plot a histogram of this sequence in the list. When I use standard hist funcion of matplotlib library , I get only two bars.It counts all zeros and all ones and shows me the histogram with two bars. But I want to plot in a different way. I want a no of bars = length of list and Height of each bar = value in the list at ( position = bar# ).

    Here is the code:

    def plot_histogram(self,li_input,):
    binseq = numpy.arange(len(li_input))
    tupl = matplotlib.pyplot.hist(li_input,bins=binseq)
    matplotlib.pyplot.show()


    li_input is the list discussed above.

    I can do it in a nasty way like :

    li_input_mod = []
    for x in range(len(li_input)):
    li_input_mod += [x]*li_input[x]


    and then plot it but i want something better.

    Continue reading...

Compartilhe esta Página