重叠轴标签,长度分布

时间:2017-01-18 18:16:33

标签: numpy plot label overlapping

我是python情节中的新手,我想用这段代码绘制列表:

import numpy as np
import matplotlib.pyplot as plt

alphab = [172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465]
frequencies = [24,17,21,27,10,21,26,41,23,27,25,22,21,24,31,24,19,18,27,15,29,28,22,35,35,28,30,20,29,42,39,35,30,29,38,32,35,47,30,44,55,34,41,41,46,56,39,39,57,39,58,44,51,52,51,44,57,48,50,59,54,46,64,63,56,60,74,72,75,72,60,75,74,55,75,69,70,69,73,69,63,80,70,74,62,77,69,78,70,68,68,80,71,77,79,64,83,76,64,92,77,93,86,65,88,86,79,91,79,97,87,67,83,96,94,79,102,114,89,92,90,112,100,107,98,95,99,95,96,91,103,111,85,105,113,103,105,95,110,103,111,102,102,117,127,128,110,100,122,99,126,99,113,114,133,129,118,120,105,121,112,115,118,127,109,116,96,101,98,98,94,114,94,87,83,117,87,105,120,116,96,112,92,106,115,107,98,107,87,86,111,108,113,106,109,102,89,81,102,87,124,127,116,106,98,106,117,95,113,107,121,92,102,97,94,94,122,110,101,118,112,106,95,112,115,102,136,114,125,136,126,120,116,119,140,114,125,148,126,137,140,129,134,124,141,126,127,124,162,124,137,136,137,142,156,131,153,150,139,131,143,119,145,142,135,151,117,143,151,146,149,125,109,124,135,144,125,127,161,120,158,112,129,125,134,131,130,122,118,145,132,123,131,129]
pos = np.arange(len(alphab))
plt.bar(pos, frequencies)
plt.xticks(pos, alphab, rotation=90)
plt.show()

但我得到以下内容:

not desired

我怎么能得到这个?

desired result

列表是长度分布,例如172出现24次,...,465出现129次。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

选项1
plt弄清楚

plt.bar(pos, frequencies)
# plt.xticks(pos, alphab, rotation=90)
plt.show()

enter image description here

选项2
搞乱步骤

plt.bar(pos, frequencies)
plt.xticks(pos[::50], alphab, rotation=90)
plt.show()

enter image description here