The following handles the first two plots:
data = [228782,38376,1416068,15177,3267,37238,43946,16882,1032,18015,32867,99886,10837,539578,2097,243504,721254,821,7264,24889,11301229,45200,1489405,106374,86755,117564,1195884,35285,1,1,69718,49305,99705,755060,172177,90544,375,13231,41636,2194328,445222,4151167,16397,13233,16167,28013,23123,20600,279078,204561,903049,1077988,3175300,133098,313077,150900,7916,7192,27825,11757,131951,36491,412661,13770,234963,14,27165,2655993,35906,4726736,1400946,50211,970,12991,500415,49638,227901,113491,34705,3601896,13206,2,163363,1763238,704929,17683,3345746,6169795,50960,10562405,19964,8768,60654,36688,408987,5491596,9198,3555,6956,44754,24177,44582,961052,53915,136564,88098,2506,4963972,30797,182620,120865,255538,82780,62005,31621,1878092,9538,3,104934,190948,32669,144033,1476,10792,490043,44086,16947,65156,4,67559,91119,158176,41496,444282,716632,370458,3497,113392,14303,14122,29358,35527,3359,1283,49466,964715,2231204,222141,215161,295728,32342,13462,2479807,5400340,388405,67750,22347,1491,106668,1533418,535,10953,10796,286274,33799,68004,11507,84894,353376,963503,2450530,161553,146589,796,94487,124304,4909631,31693,7574328,321190,15335,243789,71551,4162413,292380,140728,611758,536,120032,549,32414,52314,3321,5251,17321,290913,224,138860,2175516,13886,3674482,308513,2179765,11830,2228414,128376,103459,100288,442028,2685164,176,2,821791,780,533,125481,140268,96293,223237,22322,51114,10292,126129,271666,104450,5073589,1767339,250,32306,154856,20439,2160830,5,310789,896015,754529,38198,1445987,12020931,795411,25003,538,36861,18150,991877,1962984,48752,82654,3963056,6494512,79644,12438,20884,7,3849311,1495,6469,291234,72614,5439,26130,274373,12597,811805,3,295383,99982,22564,38928,92,1907481,3075,729,658168,1165,951107,128879,680182,3601,4208,2026,108807,746024,2866765,1505305,344209,223629,121982,77107,20725,12501,6308,858843,3675204,5050872,152005,36862,238924,52329,2049905,29376,855373,3766990,1756,1516744,22267,1515269,616,10687,17424,30983,314870,5017553,110463,50482,34061,33543,107524,619803,1108,190765,108684,2452800,90389,3213,871491,3760,773869,63341,5691,23539,20696,36256,373034,8614,4724,3692,13870,105831,26373,3188,160035,27253,1281,3332,43168]
rank = sorted(list(range(1, len(data)+1)))
freq = np.array(sorted(data, reverse=True))
plt.figure(figsize=(8, 6))
plt.xlim(1, 10**3)
plt.ylim(1, 10**8)
lines = plt.loglog(rank, freq, marker=".")
plt.plot([1, freq[0]], [freq[0], 1], 'r')
Now I am trying to add this log-normal plot of:
# log-normal
x = np.ma.log(freq)
avg = np.mean(x)
std = np.std(x)
pdf = lognorm.pdf(x, avg, 0, np.exp(std))
plt.loglog(pdf, x, marker='v')
# plt.plot(pdf, x, 'gv-')
title('Zipf plot of Airport frequency')
xlabel('frequency rank')
ylabel('airport frequency')
grid(True)
plt.show()
This is what produce by the both code blocks and as you can see the third plot is not showing:
Appreciate any insight on how to get this to work. I running on Win10 using Python 3.7 with latest versions of matplotlib and other packages.
Both plots are actually being plotted, but the x and y limits you're using are ignoring your log-normal data. I copied and ran your code exactly, except I changed the limits to
plt.xlim(10**-3, 10**3)
plt.ylim(10**-1, 10**8)
and this produced the plot below
When I want to adjust the x and y limits for my plots, I typically do that at the end right before plt.show()
or when I define the xlabel
and ylabel
. I also will do min(xdata)
and max(xdata)
to get the limits that show all the data (you can also add offsets as necessary).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.