0

I have the following code:

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter

hour_of_day = [17, 13, 21, 21, 16, 15, 9, 10, 12, 11, 10, 1, 5, 13, 13, 18, 21, 23, 23, 14, 11, 12, 15, 17, 9, 19, 7, 20, 20, 21, 21, 19, 2, 8, 23, 8, 8, 10, 15, 11, 19, 18, 20, 22, 22, 0, 0, 10, 13, 11, 16, 18, 18, 19, 19, 19, 23, 4, 6, 11, 15, 14, 16, 21, 20, 20, 21, 21, 14, 15, 19, 20, 23, 6, 6, 14, 15, 0, 1, 1, 12, 20, 21, 21, 3, 2, 5, 6, 6, 7, 10, 10, 11, 12, 12, 9, 14, 14, 19, 15, 16, 21, 21, 22, 22, 20, 4, 6, 7, 17, 17, 18, 18, 19, 8, 14, 13, 20, 14, 0, 6, 4, 7, 13, 12, 12, 17, 19, 21, 22, 0, 0]
fig, ax = plt.subplots()
counts, bins, patches = ax.hist(
    hour_of_day,bins=range(25), normed = False, color = 'g')

plt.plot(bins)
plt.show()

It generates the (almost) expected figure. In particular, it renders an unexplained blue(!) diagonal. What is this line? Where is it coming from? How can I disable it?

For reference, here is the result I get:

enter image description here

3
  • 1
    remove plt.plot(bins) Sep 16, 2014 at 12:19
  • 2
    @behzad.nouri Why don'yt you post it as an answer writing one more line as explanation?
    – wagnerpeer
    Sep 16, 2014 at 12:21
  • 2
    @pwagner because this is not a question which would help others, and it is better to be deleted by the OP Sep 16, 2014 at 12:34

1 Answer 1

1

Here, your histogram is generated by ax.hist( hour_of_day,bins=range(25), normed = False, color = 'g').

The blue diagonal is caused by the call to plt.plot(bins), which makes an x-y plot of bins vs your x-axis (in this case also bins). You can just delete this line and the unwanted blue line will go away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.