An official example, doing a histogram, using the path patch method. Seemingly deal with the larger data used, followed by another method of comparison, suspense
ImportNumPy as NPImportMatplotlib.pyplot as PltImportmatplotlib.patches as PatchesImportMatplotlib.path as pathfig, Ax=plt.subplots ()#fixing random State for reproducibilityNp.random.seed (19680801)#histogram our data with NumPyData= NP.RANDOM.RANDN (1000) N, bins= Np.histogram (data, 50)#get the corners of the rectangles for the histogramleft = Np.array (bins[:-1]) right= Np.array (bins[1:]) Bottom=Np.zeros (Len (left)) Top= Bottom +N#We need a (numrects x numsides x 2) numpy array for the path helper#function to build a compound pathXY =Np.array ([left, left, right, right], [bottom, Top, top, bottom]]). T#get the Path objectBarpath =path. Path.make_compound_path_from_polys (XY)#Make a patch out of itPatch =patches. Pathpatch (Barpath) ax.add_patch (patch)#update the View limitsAx.set_xlim (Left[0], right[-1]) Ax.set_ylim (Bottom.min (), Top.max ()) plt.show ()
Python Picture Histogram