python - Multiple Broken Axis On A Histogram in Matplotlib -


So I have some data that I want to plot through the frequency density (unequal square width) histogram, and some Search through online, I made it so that I could get permission to do this.

NMP import as import matplotlib.pyplot plt plt.xkcd () freqs = np.array ([3221, 1890, 866, 52 9, 434, 494, 382, 92, 32, 7, 7]) bins = np.array ([0, 5, 10, 15, 20, 30, 50, 100, 200, 500, 1000, 1500]) widths = bins [1:] Cans [: - 1] Heights = Frox. Slipes (np.float) / width plt.exlable ('cost in pounds') plt.ylabel ('frequency density') plt.fill_between (bins.repeat (2) [1: -1], heights .repeat (2) , Facecolor = 'steelblue') plt.show ()

As you can see, this data is spread over thousands of x axis and on the y axis (density) small data ( & Lt; 1) leads to huge data (> 100). To solve this I need to break both the axes. I have found so far to help, which is the hardest to use, will you be able to help? Thanks, AJ.

You can use the plot only once. Setting xtick labels to represent uninterrupted values ​​

with logarithmic y scale < / P>

  Import numpy NP as import matplotlib.pyplot as plt plt.xkcd () fig, ax = plt.subplots () freqs = np.array ([3221, 1890, 866] , 52, 9, 434, 494, 382, ​​92, 32, 7, 7]) Freqs = np.log10 (freqs) bins = np.array ([0, 5, 10, 15, 20, 30, 50, 100, 200, 500, 1000, 1500]) width = 0.35 Ind = NP. Lane (Frequance)) rects1 = ax.bar (Ind, Freq, width) plt.xlabel ('cost in pounds') plt.ylabel ('frequency density') tick_labels = ['{0} - {1}'. Format (* bin) in zip (bins [: - 1], bins [1:]) ax.set_xticks (ind + width) ax.set_xticklabels (tick_labels) fig.autofmt_xdate () plt.show ()  < / Pre> 

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -