Hello, try doing:
import matplotlib.pyplot as plt import random rolls = list() for i in range(1000): rolls.append(random.randint(1,6)) plt.hist(rolls, bins=6) plt.show() Reason why your histogram is weird is because you only can have 6 bins in your example. But the default bin number for hist function is 10. The borders of bins are therefore set at half intervals. When you roll 1, bin 0 to 0.6 gets incremented, when you roll 2.2 bin 2-2.6 gets incremented, but the bin 0.6-2.2 never does. Follow me? (also I just made those numbers up...) Point is only the bottom bins of your roll values are filled which leaves a gap in your image. Dino 2014-12-03 21:51 GMT+01:00 Amit Saha <[email protected]>: > On Thu, Dec 4, 2014 at 6:45 AM, Brendan Barnwell <[email protected]> > wrote: >> On 2014-12-03 12:39, Amit Saha wrote: >>> >>> Hi, >>> >>> Please find attached a simple histogram created using the hist() >>> function. Any idea why the last two bars are squeezed into each other? >>> Is there a simple way to fix this while plotting? >> >> >> It looks like the bins are set up so that there are empty bins >> between each of the other bars. How are you setting the bins? You could >> try adjusting the bin boundaries. > > Thanks for the reply. This is my program: > > import matplotlib.pyplot as plt > import random > > def roll(): > return random.randint(1, 6) > > if __name__ == '__main__': > rolls = [] > for i in range(1000): > rolls.append(roll()) > # create a histogram plot > plt.hist(rolls) > plt.show() > > > So, just using the hist() function for now. > > Thanks, Amit. > >> >> -- >> Brendan Barnwell >> "Do not follow where the path may lead. Go, instead, where there is no >> path, and leave a trail." >> --author unknown > > > > -- > http://echorand.me > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk > _______________________________________________ > Matplotlib-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/matplotlib-users ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk _______________________________________________ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users