• matplotlib模块


    matplotlib模块

    matplotlib模块官方文档
    matplotlib是一个绘图库,它可以创建常用的统计图,包括条形图、箱形图、折线图等

    条形图

    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    %matplotlib inline
    font = FontProperties(fname = 'E:jupyternotebooksimhei.ttf')  # 找系统里的一个汉字格式
    
    # 修改背景为条纹
    plt.style.use('ggplot')
    
    classes = ['3班','4班','5班','6班']
    classes_index = range(len(classes))
    print(list(classes_index))
    
    [0, 1, 2, 3]
    
    student_amounts = [66,65,45,70]
    # 画布设置
    fig = plt.figure()
    # 1,1,1 表示的是一张画布被切割成1行,1列共1张图的第一个;2,2,1表示一张画布被切割成2行2列4张图的第一个左上角
    
    ax1 = fig.add_subplot(1,1,1)
    ax1.bar(classes_index,student_amounts,align = 'center',color = 'darkblue')
    ax1.xaxis.set_ticks_position('bottom')
    ax1.yaxis.set_ticks_position('left')
    
    plt.xticks(classes_index, classes,rotation = 0,
              fontsize = 13,fontproperties = font)
    plt.xlabel('班级', fontproperties=font, fontsize=15)
    plt.ylabel('学生人数', fontproperties=font, fontsize=15)
    plt.title('班级-学生人数', fontproperties=font, fontsize=20)
    # 保存图片,bbox_inches='tight'去掉图形四周的空白
    # plt.savefig('classes_students.png', dpi=400, bbox_inches='tight')
    plt.show()
    

    png

    直方图

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    %matplotlib inline
    font = FontProperties(fname = 'E:jupyternotebooksimhei.ttf')  # 找系统里的一个汉字格式
    
    # 修改背景为条纹
    plt.style.use('ggplot')
    
    mu1, mu2, sigma = 50, 100, 10
    
    # 构造均值分布的符合正态分布的数据
    x1 = mu1 + sigma*np.random.randn(1000)
    print(x1)
    
    
    [49.10415687 42.13858392 56.47648246 22.29624387 54.74816175 37.52879673
     40.5647323  37.35623406 49.88249427 66.49526361 28.57957141 48.24314343
     66.16698406 37.71346995 54.4376674  28.91515944 62.97130324 56.55114202
     26.16736169 67.63439685 65.68609462 31.70543114 31.97073301 49.14937432
     46.71083326 35.13809643 61.21570482 38.05121797 51.56401902 57.73105761
     49.76701361 45.74747826 53.66628682 57.21734675 40.8393499  37.490882
     56.95732936 45.18649079 62.67439248 43.87343606 50.93581412 50.74290396
     32.51700115 67.82386461 40.09000489 58.11433114 44.15277854 42.57442844
     62.86854983 41.23622077 71.4253717  63.89619733 54.48488734 41.56447742
     71.01709015 37.81086714 42.72911182 53.993755   54.443727   58.27871401
     60.63317746 47.91323486 51.83189609 47.11511674 48.63780943 35.10182419
     53.32578748 41.58923002 57.69809646 44.43512018 59.95256174 72.47548482
     50.54835118 43.0505035  34.22166021 38.08388645 57.3177316  56.83671173
     65.33965791 51.57951974 30.9125097  51.75673299 37.97601634 68.88922338
     38.07018635 66.8930613  49.52296574 49.74299969 56.95989753 48.22490552
     34.57748706 48.09947804 55.52046252 61.89629589 42.66385034 48.11629394
     52.82144167 35.76351968 51.42751237 69.06220541 65.48143465 33.74496376
     44.28839646 48.78576814 37.32286404 45.27309249 61.2050822  43.34054383
     36.82578549 58.10424119 45.92814134 48.77103502 44.02907441 52.99112607
     73.53488496 56.31060893 54.67427155 41.12691208 50.11295324 42.34060667
     39.93142978 53.44936467 53.20409277 50.27866205 59.7863997  36.86206578
     49.57957401 65.54923071 46.13727434 46.73322205 48.40937157 50.2847235
     71.11811963 61.68692731 38.44302241 37.49496409 30.00850895 54.00799499
     50.37010603 67.0157462  55.8394985  67.25724604 49.59222877 27.31076588
     49.72276892 63.09443411 50.59306595 45.07599133 58.36296735 47.17407993
     57.38439362 45.85904253 49.4682399  41.8785644  39.01025351 34.62328402
     55.67742645 38.6778194  55.33044391 72.18799655 56.40307816 60.46764561
     52.00999465 55.69413419 40.8051088  50.10048256 33.05816032 48.23211303
     55.40303049 50.22563525 49.58579072 44.45965962 40.08575631 47.86257811
     43.49381088 37.87321877 55.29985467 29.42302045 41.53221457 28.78420501
     33.92352933 49.95112518 51.3757408  48.31894307 58.6812119  58.17330443
     56.24867702 39.61714693 54.78316648 55.88431592 65.08952344 40.68765652
     51.45663146 54.08334717 54.01829427 27.85210492 43.75483189 43.53730918
     54.84409087 40.93882769 38.28821771 57.91735706 58.83300761 57.95860294
     55.35620107 59.41792703 48.65426313 33.12778864 43.03322163 45.09297414
     23.92029531 59.17832275 51.05690266 43.65253251 50.63507228 39.49550629
     36.54340799 61.05582003 38.60245876 50.85452321 51.13680864 63.93080161
     53.59518362 44.18055918 50.00353074 57.33865429 48.72013104 56.65074065
     60.32394737 46.08612945 52.5216121  40.55182131 63.17292588 27.80283376
     59.45883765 54.2634933  55.7924821  63.73963234 63.47203872 63.86898605
     43.32248401 40.02074782 55.97866093 65.44098272 51.65981458 56.37920312
     44.72285836 53.38030028 45.24444185 47.22097744 46.66185967 44.10097886
     57.2733147  54.55157602 53.15477887 56.65373654 46.29501174 49.24432963
     61.4812996  42.25872932 45.35325353 40.86944166 55.51191561 53.50301562
     50.92688217 50.756645   48.32850902 58.59794246 60.31171564 72.38699778
     36.28887642 55.5692228  24.33976497 56.39915597 58.03437434 55.41239716
     50.22702872 60.06571969 40.18659061 57.17258867 69.60299168 77.26357492
     56.62055835 41.92532391 38.48958968 49.52579088 37.02451468 55.77156729
     63.6570146  53.97664362 52.20639664 62.12628459 40.99742447 46.02129803
     56.90839997 36.92366616 61.88139225 52.62559441 38.80827077 59.92381037
     55.93670466 46.00150389 64.45917631 48.45407833 43.42002659 42.03875258
     51.27738619 38.74533978 37.18480726 49.54708803 43.44607696 47.62945893
     54.40723504 49.14584504 62.76668763 39.01138314 46.20445285 66.2450782
     53.74568549 37.07849979 34.07414644 47.49259252 39.51067779 64.85672426
     52.41350098 36.44983801 46.02594277 49.60369115 42.98303538 39.72704724
     52.42409579 37.42917103 36.34135261 42.1549531  52.86662356 66.3557006
     40.74737396 27.74999373 54.7823014  55.49112942 42.26201045 51.49963727
     26.59741103 45.73207074 49.25854239 78.37120804 62.31492714 64.50748108
     20.9689422  67.58211655 42.42652961 66.28024151 51.77256718 60.10662318
     28.99867707 47.42313226 53.48749249 34.48164899 66.72069379 55.03189063
     52.24086169 56.84256193 30.02919357 61.93207004 41.65356201 40.90596947
     53.17841552 67.19520491 56.31050596 68.55105737 54.85260185 44.84020119
     55.34776368 63.3108424  48.99430769 41.0489612  51.47391971 38.1013761
     39.43216658 55.08250671 30.5538352  43.37298069 36.98677211 44.42464459
     43.73482511 52.06922851 66.34016181 46.88998283 44.16449585 61.36074147
     51.68521684 53.13742321 51.50586329 48.2252941  66.5680673  40.83618122
     44.07729625 43.30572517 43.17179828 39.62904345 42.58717046 37.52321436
     58.47567174 43.53567182 47.54153626 57.52928821 45.22767201 49.14500735
     58.59689064 51.82480851 64.13466065 47.91527625 31.0069493  60.37793866
     52.14886813 33.80888992 49.15883978 44.27498437 62.80731013 30.55339875
     61.1781737  40.69802367 31.18803822 52.54264547 50.48720147 46.76266977
     44.06294505 43.89740779 54.19174301 47.09407187 63.91530482 61.77708568
     30.14285339 30.25102437 56.203564   51.65173445 51.9483891  41.02682301
     61.02672433 40.60289864 48.56095438 72.75303601 51.93448737 43.99267587
     52.72808537 47.68688652 58.92704642 54.92397795 46.12464089 67.79726087
     52.02560021 62.20553004 48.11668545 55.37501899 36.81317049 57.7439758
     60.35354009 58.41636124 20.4004687  60.22293702 36.87324813 30.46621545
     33.13937083 29.77866577 36.76619639 49.46423113 47.00556943 50.96195584
     51.13055358 46.75975434 56.95065875 48.00055382 59.51879406 51.53334623
     57.56386622 55.28909582 45.4061612  50.07059625 60.72498051 54.43380619
     48.25313058 49.35308577 40.05722481 56.45796109 40.27143814 58.74285338
     37.79428593 50.58594364 34.09690603 49.3173686  56.57508712 69.13928198
     63.78723074 57.19147807 49.20503353 58.33861466 45.34364375 62.99879334
     47.88746872 45.72740254 31.86423993 46.77328183 56.59236908 37.05797608
     49.48589824 33.41049759 44.73962984 50.12392098 38.01843456 39.12435347
     65.88367066 43.58714732 44.29367172 56.51718745 33.69800918 60.58826103
     61.62839258 56.99941917 62.40884049 56.59972656 52.74076327 41.91242562
     23.15582184 53.54756743 53.34670848 56.15422882 43.46423981 43.29780719
     66.8630013  37.46781532 39.41376054 48.87592874 65.81727257 41.86249102
     43.81095261 66.0926052  48.06274889 46.40988291 63.17700834 41.30466611
     44.72705648 54.55638632 58.48684216 52.38325706 44.19603489 40.37111534
     28.85653722 34.09054915 39.73607756 60.85059057 36.42236536 46.73141874
     42.00131746 67.46281503 73.40763431 59.27236994 43.61286061 60.56114109
     69.40014544 42.77058788 42.02299442 50.73868956 62.70420372 49.23524793
     47.41209742 39.02619515 45.48527516 50.06798756 48.76639722 55.09279095
     47.3324739  65.2056691  57.08603532 54.70615656 56.45051821 36.72498868
     54.11835125 58.82903174 69.66506803 62.43408999 44.8766561  53.52627399
     62.50900652 50.72269136 58.10166429 44.30821941 34.79056858 57.46085196
     38.89898875 46.8490626  50.43313613 43.34062707 37.89427281 38.41600923
     57.24488685 65.2016458  40.65189408 48.45409655 50.50143042 35.88182928
     31.8013305  46.3354646  43.29878502 52.47733111 50.10031483 46.45465683
     41.49566971 54.4619481  58.4245574  60.4954009  56.70885941 54.17697624
     48.65205126 54.71845534 41.7384485  38.20497063 42.42314246 55.62298578
     54.68996756 63.85531721 28.759632   57.4810929  49.60802656 44.80568424
     44.64021654 44.53192243 47.74132657 55.86246132 49.61145809 35.3038994
     70.56051559 51.57522401 63.72126135 55.01197432 42.81441905 60.52117257
     26.71935281 58.68048301 53.46799394 71.20899816 59.5732367  43.86249788
     43.70078102 50.29898691 44.39438569 50.62267764 51.38902134 47.27445576
     40.68344053 56.5790143  67.80717051 50.07432975 62.91674851 56.77733465
     54.14755713 59.89019891 50.88822248 43.51892921 53.57974075 66.46356704
     46.98245039 51.25297488 58.53857563 59.15467633 52.34023651 60.17918478
     35.81610507 48.98865852 57.68442969 47.99146254 51.20602329 48.09847655
     45.74163033 47.14951027 44.29194268 54.98290624 60.05929107 64.34822573
     55.6289905  53.06322343 24.61092967 49.85212821 54.98608038 32.7078453
     48.76164819 49.02830426 26.48094193 55.42298334 61.60908991 46.92233732
     51.81469006 51.00450248 45.59436358 52.76403155 66.03066726 51.3596067
     32.82495989 38.86306747 45.99144517 48.74761367 47.28770941 43.95779376
     56.14619968 36.10656773 51.54048934 36.5561601  44.15641301 61.91187363
     65.4795377  60.82600305 46.99899479 61.98314024 43.34447706 46.87505848
     52.26176507 60.94448512 54.93540447 55.43853565 46.16920175 56.6362271
     47.5864662  48.89871672 44.02502084 64.0421457  60.09078445 39.67488257
     53.83018376 51.92906525 43.85607051 47.98914394 35.07321549 50.80408626
     59.24111409 51.33244888 52.90923974 55.92280249 54.2614652  39.80543229
     42.0400616  57.59202133 66.53488446 35.29853926 63.7879534  33.36396463
     47.59769841 52.63305845 37.24352429 44.25038428 53.13716411 64.15197739
     60.48790784 70.06974539 53.05443451 40.5475319  49.75151838 69.36144246
     58.0555214  36.97212705 51.76819224 42.58882306 38.6312332  56.69512798
     37.37771362 68.609112   48.16796271 41.53464365 48.36068484 54.33889258
     45.55009982 52.83151774 57.98385293 50.21788321 62.08891246 42.79099562
     57.97509624 38.49890422 61.3989778  40.60566533 32.40895712 52.22823369
     56.50967143 53.08065759 76.36619593 40.26051711 41.01334215 46.99948914
     45.9006175  46.55617363 56.49815973 34.64812693 54.46102986 44.65978927
     66.84613711 47.93927486 51.25044938 41.80725514 50.62139534 46.27106618
     51.91732427 47.73813455 54.66778462 55.63332566 48.16233672 44.25853593
     42.75817368 51.55472898 48.61145156 66.71825656 56.73934912 62.20095905
     62.18502748 56.06012945 63.72836077 57.49988035 36.66017391 35.03329808
     44.26251202 39.97710058 36.62642053 47.58262161 58.11829752 46.48161007
     59.552829   58.11997513 49.94489007 58.06862409 65.00071586 33.28790544
     45.42434277 50.93132694 53.64879446 40.69661915 36.80802709 56.32835594
     47.79355338 65.59002939 42.2611702  46.76962072 66.69582683 40.31138416
     58.18470334 43.75072311 67.5453487  45.07535697 55.15173964 41.59317102
     66.65746195 61.83661041 65.6943014  43.49054635 56.55609611 42.88656371
     50.0497152  63.42989748 56.16555082 34.20923512 54.53136646 53.06513255
     50.44560963 40.09883232 54.10101567 50.72659792 51.87007473 49.80094859
     38.06576077 34.3200605  43.36494003 51.4546644  42.79928722 73.46362697
     64.85003697 45.15831036 57.13071621 66.75313068 34.48969147 34.5523368
     48.57982659 70.3013366  46.77160428 45.31280028 36.6400255  41.58661005
     49.82971522 54.54948553 60.72679427 58.42194655 62.32751235 29.88899237
     58.03109649 36.86739015 54.57837573 60.88725754 57.62898103 59.60715355
     55.26638474 48.99523954 50.48265301 55.24992419 41.32071996 44.86410243
     55.43489885 37.29877308 50.11603164 39.6830687  50.18267109 49.03915019
     39.73852798 34.82984315 45.28032275 37.60918764 60.1489137  35.61612415
     39.59469146 45.04749618 61.62405695 49.49532927 44.86531796 61.30046886
     50.19785215 55.15297568 45.92742796 45.55927428 58.81855508 37.26667751
     60.08006386 52.18428016 69.36512944 40.1726569  27.79698154 50.92627242
     53.59958271 54.30131097 53.02167137 33.37088422 51.83285018 43.58177022
     34.86123525 45.52398882 14.85390171 42.83327586 31.42493453 50.95737107
     62.02873183 41.33634473 48.31825904 47.23330875 63.15698926 63.33159078
     39.73717066 40.19194737 36.72491532 67.11749202 44.08039076 49.08775222
     58.66258017 44.86258397 40.18909686 42.03470186 38.39243927 57.40815527
     42.70790633 50.49457117 58.76015001 58.36145914 45.12785507 54.92877521
     50.46646954 49.99155422 40.17463249 44.68368101 41.65537391 55.68893817
     62.08579846 38.85327715 64.12134471 44.2706532  47.74505103 57.00956492
     37.59033848 59.39457805 38.57959219 48.58693607 43.81139975 42.90678343
     59.9251192  57.14494073 51.4032319  50.34710312 52.42911505 42.19689099
     28.10291091 51.3860998  42.28247039 49.85728388 54.14305281 57.51176931
     41.1070322  61.12677354 74.95458911 52.89100475]
    
    # 构造均值为50的符合正态分布的数据
    x1 = mu1 + sigma*np.random.randn(1000)
    x1
    x2 = mu2 + sigma*np.random.randn(1000)
    x2
    
    array([110.84443503,  95.65806077,  83.91718776, 104.7503521 ,
            94.57901157, 109.58932913, 100.08646768, 100.21773516,
           100.02515422, 108.20312625, 111.78995375, 106.26149774,
            94.61675894, 100.46151289,  99.82750402, 104.24730045,
            92.6954865 , 106.2465308 , 105.26698725, 104.58756618,
           116.19882825, 102.15440445,  87.73760109, 105.17655697,
            79.44125882, 107.60877082,  98.0076041 , 109.5658858 ,
            97.4279394 , 102.2590176 , 100.99598229, 109.347777  ,
           112.45014174, 104.85117868,  99.5079622 , 102.89868555,
           102.8523036 , 110.23855712,  85.12840871, 120.12160469,
           121.37882095,  99.12445677,  86.91156845,  86.23961529,
           103.09986236, 100.22883259, 120.49416614, 108.12255519,
            96.93440291,  96.40872134, 113.27487812, 114.29101501,
            85.12101733, 107.32053001,  97.52075904, 100.53284867,
            99.88948282, 110.44057119, 103.99261043, 106.99517094,
           105.45526069,  94.39939147, 101.49348631,  85.41193048,
            98.5597457 ,  90.10252019,  98.84551836, 111.61455444,
            93.19693106,  96.83486496,  85.22922341, 102.24398309,
           106.92543045,  97.97520307,  92.9016217 ,  92.3958072 ,
            94.41960266, 106.06081981,  92.93099984,  98.25840195,
            79.00875095,  94.0197036 ,  95.17484896,  90.27821815,
            97.09684662,  95.00988683, 104.85761447, 112.28804078,
           117.00176404,  85.58234365,  75.42970793,  96.82285303,
           111.42404953,  99.32672487,  95.25878922,  98.88175347,
           102.38325357, 105.72334682, 117.54902021, 108.42707038,
            94.74697793, 105.00678908, 101.74118083,  94.96685238,
            94.26426826,  93.01350222,  99.78184681, 102.86225728,
           103.0376997 , 118.68518081, 102.20308964,  90.55146325,
            95.79045184, 118.36113629,  96.14293047, 108.49378553,
           102.32537592, 102.51025158, 104.3850011 ,  95.83975888,
            80.85898351,  94.80721777,  91.58269417, 103.37566718,
           101.56822427,  93.83985129,  90.10361   , 116.39443486,
            96.84820196,  89.04216504,  95.98742046, 103.98627042,
           111.19716197, 113.37615851,  94.43706514, 111.64192415,
           112.90043978, 104.09290378, 103.53474605,  87.46106428,
           118.9690821 ,  96.15964692, 112.5682021 ,  91.92946603,
            94.06670162, 101.97804326, 110.34085422, 100.35329653,
           101.14982449, 103.82730567, 101.88014229,  86.44174454,
           129.4604248 , 109.31213526,  82.17970143, 102.9349143 ,
           109.627097  ,  98.40846892, 101.39894696, 103.77160044,
            77.22369162,  99.29360037,  96.94361136, 103.13626947,
           107.06342187,  99.12646443,  75.35570957, 102.47020915,
            95.53333846,  98.34449608,  94.27320308, 118.31435884,
           102.20306902,  93.48501392,  65.71232991, 102.8096199 ,
           104.85593106, 108.17561375, 112.87494497,  94.61622225,
           102.02859995,  90.99449325, 119.32025237, 116.59294452,
            90.92855559,  97.27076466, 117.3744434 ,  94.66421186,
            81.51871559,  88.00035846, 111.28993904,  98.55658984,
           115.87405755, 115.49425006,  82.40272556,  88.69534775,
            91.8567491 ,  88.45060648,  86.31124991,  93.23565678,
           104.82629765,  96.43017096, 106.29699669, 108.6881035 ,
           102.92812504,  88.22506891,  73.88313832,  93.36108245,
            85.4446013 , 107.78987996, 103.44884265, 105.30750908,
            92.17238037, 119.21574435,  97.12109606,  90.70132842,
           101.92214799, 114.46161554, 106.97516987,  95.70856372,
           112.25066423,  87.71028317,  95.64581052,  89.11550498,
            96.69053022,  97.09784692,  96.37871704, 106.66384439,
            87.15878027, 104.33152464,  98.12379773, 108.19967227,
           108.63728172,  93.143527  , 111.46851935,  98.78489078,
            98.35462426,  89.89160747,  95.44823613, 109.96610838,
            95.49225419,  96.86778507, 106.93626112, 108.76743774,
           112.35472295, 122.61209704,  98.80463945,  83.42770093,
            85.67113085,  86.68840164, 104.57299553,  94.65361409,
           104.42786234, 106.80342968,  84.83853486,  96.07272853,
            95.57124556, 103.69050605, 105.95044118, 106.33182926,
           111.22640989,  88.59552926, 113.22366148, 100.08538346,
            96.61454086,  96.81943814, 115.6305447 ,  89.95715809,
           104.34127275, 106.86696118,  98.3577645 ,  90.52904514,
           100.11261094, 101.57236559, 102.33368818,  98.57301552,
           103.8247666 , 112.63424776, 118.69493544,  93.49738935,
           104.09727754, 105.33926703, 119.03754659, 102.83057546,
            79.56833592,  96.77281554, 105.59962129, 107.81881577,
            99.44126508, 100.60924016, 115.51539805, 103.67572146,
           123.67926794,  93.24029512,  94.37882298,  94.98419553,
            94.99082025,  97.37533708, 120.8080477 , 110.60476796,
            79.38123641,  94.50685142,  92.44856995, 121.08340813,
           105.42279429, 104.6048533 ,  98.10843075, 114.4166214 ,
            97.8902698 , 106.24228164,  92.97490905, 112.78433628,
           126.72621198,  95.25406166, 115.50076744,  92.88199563,
           102.11570213, 103.88088647, 111.12220714,  89.85508999,
           124.64391655, 101.92943205, 101.59714597,  87.05847196,
           121.8027688 , 105.25584558,  97.09533818,  99.06779321,
           100.15860725,  85.77862767, 104.27593047, 102.86136137,
            91.94153918, 119.18025769,  76.34281656, 108.01178676,
           100.85621579,  71.77629827,  91.88620743,  82.92463522,
            73.52413538,  86.78885529, 115.25761962,  95.61495682,
           110.12770019, 101.04308092,  93.22412308, 122.42361189,
           108.44919358, 102.16491648, 125.86422295,  94.96040539,
           100.71933805, 102.33495928,  96.75367527,  79.26232952,
            92.1145074 , 105.15277033, 104.02015427, 109.34628336,
           115.2936897 , 118.5027903 ,  94.666952  ,  79.19766546,
            97.86760156, 104.17338326, 102.99831709,  86.12701622,
           113.3814446 , 103.98091264, 113.71985223,  85.85756797,
            95.71091738, 111.62716339,  96.34215047,  86.86363751,
           114.48248344,  98.717129  ,  98.29476091, 112.97431243,
            99.75540438, 110.76617776, 105.69724119,  98.528935  ,
            97.17077215, 107.94237708, 112.59267824, 111.44441608,
            97.99598366, 104.17407744,  99.27757625,  95.42541368,
            93.1026958 , 103.48275926, 123.04397563, 106.12212553,
           102.75855046,  97.92411062,  98.96172598,  89.18552987,
           113.16093462, 106.80298733,  99.53939489, 103.48260409,
            94.60589377, 100.99053737,  90.22294697,  97.22223588,
           104.27668371, 100.79467348,  93.77118352,  92.61643745,
           105.10933305,  98.41998535,  97.78944578, 115.12160323,
           105.51555743, 109.69991213,  92.96163   ,  90.25139389,
            86.8638866 , 101.47133767, 118.31903948,  95.3856373 ,
           117.80526354, 112.84559434,  90.06916533,  97.62997485,
            92.58613134,  94.52276444,  99.2473333 , 102.36346793,
           108.37319297, 111.17135144, 108.10738404,  94.45490119,
            76.75564448, 102.69781418,  88.31863727, 106.55566515,
            93.85436026, 105.94481653, 105.93127714,  95.93475744,
           121.93515244,  93.1401534 ,  96.47785266,  95.70439816,
           100.56895286, 112.39178106,  95.23546955, 107.82190226,
           106.03666981, 105.4201155 ,  85.61648264, 118.00040754,
           110.22579339,  95.28319021, 115.69990876,  85.97142366,
            89.38634142, 107.54902476, 119.88265448, 113.09129229,
           102.38739146,  99.83715803,  92.5023518 , 103.18020078,
           109.65643669, 102.8308534 ,  76.38476832, 111.77458177,
            98.36835044,  91.18363136,  84.88786742, 107.83056053,
           103.1385507 ,  93.43427504, 108.20636392, 109.72925888,
           104.28421765, 103.87060841, 113.82130955,  91.1907363 ,
            92.44254604,  79.99313372,  89.04135688, 106.53676898,
            90.52494902,  84.32626796,  85.02729721,  94.03362589,
            95.59660682, 104.91181044, 100.69011834, 109.49999003,
            94.63069027,  94.33286938,  98.91115538, 114.5772484 ,
           118.1800395 ,  91.22309637, 102.79641015, 107.54951989,
           109.01167953, 118.47917583,  82.12059973, 102.81279108,
           105.40195521,  95.21842122,  93.555618  ,  85.6572658 ,
           107.61809624,  97.35259312,  92.47801813, 105.08406421,
           102.68991747,  94.88314282, 119.38290681, 105.07125737,
            91.97559063, 113.56516485, 118.96418297,  86.57210881,
            95.26082674,  90.55225707, 101.58325639,  91.48892841,
            95.42589286, 101.18224259,  98.86055786, 111.78636822,
            98.26022711,  94.96714251, 101.34271113,  89.60718784,
            98.64569837, 103.05355759,  84.31150794,  89.81505407,
            84.43444272,  95.80289614,  92.59955447, 114.68618014,
            89.18356698, 108.26169875, 113.8244055 , 105.29218967,
            79.23289104,  95.14369136, 115.75933761,  98.48512768,
            97.07184408, 107.98946061, 108.82404703,  84.11146295,
           102.95531666,  80.59242027,  94.96512038, 105.99231616,
           104.2968808 ,  96.49976009,  93.67360761,  94.97036807,
           103.67794541, 115.6463233 ,  99.84634944,  96.72590782,
           108.87575347, 115.75935234,  87.79304148,  95.50798656,
           124.76733179, 102.89566812, 118.28822973, 104.21496788,
            94.714198  ,  86.48356333,  97.61245737,  97.77983251,
           107.7409013 , 110.47608811,  90.84748914, 111.38612442,
           100.39932422, 103.45913932, 101.69867791, 119.94468812,
            91.03798717,  92.79041822, 116.37723903,  98.86175457,
            97.1925294 ,  97.77685329,  99.80782894, 102.13843541,
            95.91793029, 105.16256006,  88.38353992,  87.74504431,
           103.9705686 , 115.07571449,  94.07549069, 113.45157967,
            91.31056305, 102.08487113,  93.08635069,  94.6239979 ,
           116.17380082,  99.64189424,  96.36246273, 100.53533973,
           102.76548048, 110.5630996 ,  92.60099722, 119.18961844,
           115.05396823,  91.94614824,  74.45496836,  89.69152776,
           122.62188385,  92.36727803, 108.36880926, 117.23594433,
            97.19422806, 102.30091   ,  91.08538045, 103.9404471 ,
            93.99184436,  90.17020575,  92.96323538,  98.43785241,
           105.17221016, 108.11613735, 110.85380084,  99.93170447,
           113.3631851 , 114.32276291,  98.74980352, 104.34241355,
            94.45404911, 103.46750439,  98.0474177 , 106.56708921,
           104.33749077,  90.78440333, 112.85744902,  94.57401678,
           107.49393373,  95.74733878, 100.46091288, 120.52723277,
           103.65703506, 101.0762097 , 118.09669924, 103.60339553,
           101.94098889, 117.18506029, 118.28352355, 104.8484509 ,
            95.69025632,  96.88323038, 102.79204737, 126.11289576,
           104.51367407,  88.89303742, 113.79485898, 109.10875277,
            86.98544489,  95.64732415,  95.5303956 ,  94.48529404,
           118.08608059, 102.17399756,  95.18506066,  98.57930211,
            90.89296165,  89.90451847, 111.76615176,  79.76771551,
            85.23105583,  99.96701752,  96.07843568, 106.59074737,
           101.86230682,  74.72976417, 110.38115093, 103.24035914,
            98.78165396,  94.0594029 ,  89.1736221 , 110.47884415,
           100.72587124,  92.6998379 , 114.84465529,  95.24120211,
           104.47644941,  97.63475133,  84.13122986,  99.5606235 ,
            96.32784626, 111.70131452,  93.52509069,  84.68173125,
            99.93815021,  94.1708108 ,  81.04637889,  88.8383889 ,
            86.821464  ,  83.91400139,  89.53315255, 104.33512368,
            97.19695022, 106.04056839, 112.48037074, 104.70859583,
           104.3028887 ,  87.37092839, 110.64445753, 103.57467599,
           105.66771092, 112.78399934, 102.60177056, 117.09186006,
            95.19342768,  99.44420619, 101.34970651, 105.14591167,
            95.93996106,  83.92855896, 103.71699657,  97.29160301,
           106.18188617, 112.82388827,  99.42562312,  91.91095632,
           105.50657467, 102.1264053 , 106.71688242, 109.85697442,
            95.53412762,  95.98612603, 105.03763993, 103.22236735,
            91.23743658, 110.19921881,  85.72517541,  98.50903148,
            95.19560901,  87.94758102, 103.45705337,  83.41164452,
            86.55810226,  94.59737086, 106.69685303, 101.15138233,
           112.97384304,  74.29935004, 101.74290287,  88.66336513,
            85.6176315 , 126.24229877,  90.13869928,  89.78272371,
            94.21083339,  87.6498004 , 111.92197258, 110.60250674,
           108.96526572, 103.74277943,  93.99680174,  92.71959163,
           104.42670488,  96.09733213,  92.84226933, 102.92632305,
            90.17223892, 104.97955891, 119.30878445, 103.01538128,
           104.34065345,  86.64078658, 100.03093177, 105.82115827,
           106.6752964 ,  99.79156086,  82.19968772,  80.36507051,
            99.62971723, 100.11107203,  89.63211688, 105.84048792,
            91.80297156,  87.23044046,  86.49689664, 112.82692632,
           102.90883498,  99.84357773, 102.18615015, 100.20294393,
            93.3301385 ,  87.03965266,  99.62944345,  96.22493412,
           111.94393817, 104.41766757,  90.88720551,  90.42925929,
            89.31431731, 101.41497375, 131.32275168, 105.92531394,
           108.13074235,  94.22617551,  98.41225587, 111.02094915,
           101.96319365, 114.42339342,  95.71337058,  89.93447655,
            88.93312905,  96.15754628, 122.51063413, 112.17886796,
           106.94029197, 116.31535336, 101.8396883 ,  91.93445817,
            95.10659685,  89.50300639,  96.65336774, 117.92847216,
           113.8104818 ,  87.66077505,  97.20847846,  99.0156337 ,
            86.6727388 ,  86.07649787,  97.50753679, 101.32617451,
           105.65567937,  94.18531045,  99.07506173, 131.37690471,
            92.83871606, 108.12004885,  88.65668548,  93.68386484,
            93.23474169, 104.21721557,  85.03407675, 107.11445545,
            87.64980974,  85.94502493, 100.8480769 ,  87.18367781,
            93.0355465 ,  98.0195253 ,  85.87017116, 102.72333582,
           102.63147704, 103.34721086, 109.41687895, 105.23802496,
            91.81948758, 108.51186945,  97.39630831,  84.27110129,
            91.00891537, 115.7975187 , 101.11080961,  91.75969635,
           103.4308927 , 105.20097937,  98.5049846 , 104.00733416,
           110.10812023, 115.23344352, 108.46235455, 116.52419961,
            92.47705863,  99.08167502, 109.85067936, 113.23505177,
           119.50415857,  93.01605762,  94.14487472,  86.86848274,
           100.26334975, 126.25625431,  97.68086356,  89.25671237,
            89.35464521,  94.85548714,  97.06729608,  97.04261401,
           104.30981301, 113.67008053,  87.4088062 ,  95.72111946,
           120.06626433, 108.34183663, 111.0439445 , 111.23347111,
           102.97466628,  97.41177936, 101.67883422,  87.64797539,
            95.40225551,  95.7060787 , 111.69306719,  87.89319312,
           112.28965259,  87.80631034, 105.34548805,  96.91421249,
            87.91060339,  79.69891049, 103.09968577,  81.08051562,
           104.46191539,  91.83619055, 107.27292409, 115.3236448 ,
            89.68135206, 124.5994786 ,  99.53361594,  84.34634362,
            83.68807651,  93.78586936, 111.82824737,  90.8516398 ,
            86.01201678, 116.80005954, 101.46586953,  92.63508296,
           105.32489734,  95.14387578, 103.75668402, 114.21489984,
           103.09438513,  84.64957844,  96.51548376,  80.84844088,
            90.35582847, 118.9984164 ,  91.37392623,  98.27925881,
           116.34640007,  97.90251197, 117.59960902, 101.10791981,
           101.12691188, 107.00644035,  88.35293685,  97.632047  ,
           102.23501737, 120.54693878, 107.1828496 ,  78.06036982,
            86.92703803, 105.51648375, 100.18717412, 101.22153406,
           113.65317745,  92.98290053, 102.67570114, 102.90433344,
           112.32821597, 102.04643063,  87.05878653, 118.26870904,
            90.05459575,  99.84755141,  94.35200186, 105.77575411,
            89.67539742, 102.0336277 , 103.33580588, 100.25602933,
           114.42406662, 119.86957102, 102.19018747,  89.75339472,
           111.39388739, 113.08733043, 105.28205013,  93.8738166 ,
            89.96085668,  84.45085002,  80.46758318,  94.53113473,
           102.63153577,  97.68413315,  85.26750449,  86.74112468,
            98.50835555,  97.57815723,  89.35769192,  85.69537342])
    
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    # bins=50表示每个变量的值分成50份,即会有50根柱子
    ax1.hist(x1, bins=50, color='darkgreen')
    
    ax2 = fig.add_subplot(122)
    ax2.hist(x2, bins=50, color='orange')
    
    fig.suptitle('两个正态分布', fontproperties=font, fontweight='bold', fontsize=15)
    ax1.set_title('绿色的正态分布', fontproperties=font)
    ax2.set_title('橙色的正态分布', fontproperties=font)
    plt.show()
    

    png

    折线图

    import numpy as np
    from numpy.random import randn
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    %matplotlib inline
    font = FontProperties(fname='E:jupyternotebooksimhei.ttf')
    
    # 修改背景为条纹
    plt.style.use('ggplot')
    
    np.random.seed(1)
    
    # 使用numpy的累加和,保证数据取值范围不会在(0,1)内波动
    plot_data1 = randn(40).cumsum()
    print(plot_data1)
    
    [ 1.62434536  1.01258895  0.4844172  -0.58855142  0.2768562  -2.02468249
     -0.27987073 -1.04107763 -0.72203853 -0.97140891  0.49069903 -1.56944168
     -1.89185888 -2.27591324 -1.1421438  -2.24203506 -2.41446327 -3.29232169
     -3.25010794 -2.66729273 -3.76791191 -2.6231882  -1.72159748 -1.21910314
     -0.31824719 -1.00197505 -1.12486527 -2.06063471 -2.32852279 -1.79816732
     -2.48982807 -2.8865816  -3.5737543  -4.41895994 -5.09020607 -5.10287067
     -6.22018102 -5.98576532 -4.32596314 -3.58391898]
    
    plot_data2 = randn(40).cumsum()
    plot_data3 = randn(40).cumsum()
    plot_data4 = randn(40).cumsum()
    
    plt.plot(plot_data1, marker='o', color='red', linestyle='-', label='红实线')
    plt.plot(plot_data2, marker='x', color='orange', linestyle='--', label='橙虚线')
    plt.plot(plot_data3, marker='*', color='yellow', linestyle='-.', label='黄点线')
    plt.plot(plot_data4, marker='s', color='green', linestyle=':', label='绿点图')
    
    # loc='best'给label自动选择最好的位置
    plt.legend(loc='best', prop=font)
    plt.show()
    

    png

    散点图 + 直线图

    import numpy as np
    from numpy.random import randn
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    %matplotlib inline
    font = FontProperties(fname='E:jupyternotebooksimhei.ttf')
    
    # 修改背景为条纹
    plt.style.use('ggplot')
    
    x = np.arange(1, 20, 1)
    print(x)
    
    [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]
    
    # 拟合一条水平散点线
    np.random.seed(1)
    y_linear = x+10*np.random.randn(19)
    print(y_linear)
    
    [ 17.24345364  -4.11756414  -2.28171752  -6.72968622  13.65407629
     -17.01538697  24.44811764   0.38793099  12.19039096   7.50629625
      25.62107937  -8.60140709   9.77582796  10.15945645  26.33769442
       5.00108733  15.27571792   9.22141582  19.42213747]
    
    # 拟合一条x²的散点线
    y_quad = x**2+10*np.random.randn(19)
    print(y_quad)
    
    [  6.82815214  -7.00619177  20.4472371   25.01590721  30.02494339
      45.00855949  42.16272141  62.77109774  71.64230566  97.3211192
     126.30355467 137.08339248 165.03246473 189.128273   216.54794359
     249.28753869 288.87335401 312.82689651 363.34415698]
    
    # s是散点大小
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    plt.scatter(x, y_linear, s=30, color='r', label='蓝点')
    plt.scatter(x, y_quad, s=100, color='b', label='红点')
    
    ax2 = fig.add_subplot(122)
    plt.plot(x, y_linear, color='r')
    plt.plot(x, y_quad, color='b')
    
    # 限制x轴和y轴的范围取值
    plt.xlim(min(x)-1, max(x)+1)
    plt.ylim(min(y_quad)-10, max(y_quad)+10)
    fig.suptitle('散点图+直线图', fontproperties=font, fontsize=20)
    ax1.set_title('散点图', fontproperties=font)
    ax1.legend(prop=font)
    ax2.set_title('直线图', fontproperties=font)
    plt.show()
    

    png

  • 相关阅读:
    【剑指offer】面试题16、反转链表
    【剑指offer】面试题15、链表中倒数第 K 个结点
    【剑指offer】面试题14、调整数组顺序使奇数位于偶数前面
    oracle sql与调优
    linux 常用命令记录 持续更新
    函数重载中形参的const
    mem_fun_ref和mem_fun的用法
    c++风格的格式化输出
    count_if函数里面的第三个参数的书写方式<<0926
    操作符重载(++,+,输入输出,强制类型转换)
  • 原文地址:https://www.cnblogs.com/Dr-wei/p/11052141.html
Copyright © 2020-2023  润新知