• Pandas入门之十九:画图


    已信任
    Jupyter 服务器: 本地
    Python 3: Not Started
    [7]
    
    
    
    import pandas as pd
    import numpy as np
    
    UsageError: unrecognized arguments: 设置这行代码,显示
    [4]
    
    
    
    df = pd.DataFrame(np.random.randn(10,4),index=pd.date_range('2020-1-1',periods=10),columns=list('ABCD'))
    df
    A    B    C    D
    2020-01-01    0.846958    -0.092453    1.439972    -1.736005
    2020-01-02    0.199984    -0.822618    0.756459    -0.566921
    2020-01-03    -0.400146    0.505496    -0.306564    0.920308
    2020-01-04    0.222298    -0.985005    1.126557    2.711075
    2020-01-05    1.952021    1.096278    -0.085026    0.335684
    2020-01-06    -1.359681    1.493068    -0.736807    -0.846511
    2020-01-07    -0.837022    -1.017107    -0.444694    0.689624
    2020-01-08    0.097225    1.996268    0.703147    -0.461194
    2020-01-09    0.749375    0.003991    -0.871616    0.287275
    2020-01-10    -0.733558    0.575336    1.087097    0.201447
    [11]
    
    
    
    %matplotlib inline # 设置这行代码,显示
    df.plot()
    UsageError: unrecognized arguments: # 设置这行代码,显示
    [12]
    
    
    
    df = pd.DataFrame(np.random.randn(10,4),columns=['A','B','C','D'])
    df
    A    B    C    D
    0    -0.220509    -0.042927    -0.238487    1.672412
    1    -0.164110    -0.507156    -0.403201    0.212512
    2    -0.213318    0.100192    1.569447    1.140537
    3    0.899244    -0.773582    0.186109    0.630794
    4    -0.065581    -0.331992    0.296159    -0.477399
    5    -0.681295    -0.035207    -0.843813    0.294918
    6    0.447513    2.029172    -0.418954    0.435755
    7    2.448048    0.931032    -0.470845    -1.186709
    8    -0.318224    -1.299177    0.344508    -0.996497
    9    0.230928    0.715940    -0.567065    -0.009406
    [13]
    
    
    
    df.plot.bar()
    <matplotlib.axes._subplots.AxesSubplot at 0x24f7fe441d0>
    
    [14]
    
    
    
    # 堆积条形图,h表示水平
    df.plot.barh(stacked=True)
    <matplotlib.axes._subplots.AxesSubplot at 0x24f7ff59470>
    
    [15]
    
    
    
    df = pd.DataFrame({
        'a':np.random.randn(100)+1,
        'b':np.random.randn(100),
        'c':np.random.randn(100)-1
    },columns=['a','b','c'])
    df
    a    b    c
    0    0.000225    -0.802291    -2.977373
    1    2.643898    -0.722520    -1.057299
    2    1.387954    -1.036934    -1.058767
    3    0.581279    -1.228817    -1.139152
    4    -0.401500    -1.500153    0.081929
    ...    ...    ...    ...
    95    2.895006    0.212231    -1.123560
    96    0.641197    0.207960    0.833677
    97    0.837922    0.228554    -0.961109
    98    2.107162    -0.056751    -2.883269
    99    0.586976    -1.269353    -0.343638
    100 rows × 3 columns
    
    [16]
    
    
    
    df.plot.hist(bins=20)# bins=20是区间显示
    <matplotlib.axes._subplots.AxesSubplot at 0x24f00052a90>
    
    [17]
    
    
    
    df.plot.box()
    <matplotlib.axes._subplots.AxesSubplot at 0x24f7ff44e80>
    
    [22]
    
    
    
    # 区域块形图,这个代码错了
    # df.plot.area()
    [23]
    
    
    
    # 散点图
    df = pd.DataFrame(np.random.randn(50,4),columns=['A','B','C','D'])
    df
    A    B    C    D
    0    0.976834    1.149036    -0.350094    0.547278
    1    1.076609    -0.729466    0.805290    0.077687
    2    0.905936    -1.384177    0.945078    2.239078
    3    -0.769447    -0.833319    1.633905    0.195962
    4    0.337959    0.195163    0.052347    -1.759461
    5    0.291865    -0.140926    -0.171821    -0.193732
    6    -0.030381    1.252231    -1.371790    0.955666
    7    -0.159967    -0.204076    -0.608549    1.698038
    8    0.025247    -0.433548    0.546536    0.317204
    9    -0.668021    0.835804    1.448863    -0.855055
    10    0.869959    -0.907479    -0.353877    -0.904369
    11    -0.266059    -1.525401    -0.820096    -1.532421
    12    -0.573746    -0.382850    -0.173064    0.609361
    13    0.499136    -0.553104    -1.271152    -0.778085
    14    -0.125324    -0.910958    -0.620956    -0.634354
    15    2.388082    1.657346    -1.980270    0.851881
    16    1.040289    0.063811    -0.644910    0.686238
    17    0.614557    0.313544    0.319014    -0.126910
    18    1.762719    -2.197812    -0.644599    1.103788
    19    -0.665237    0.588063    -1.395894    0.111074
    20    -1.197394    -0.529851    -1.176089    -0.718828
    21    0.115390    0.030522    -0.367691    0.733676
    22    0.665735    -0.498446    -0.265189    -1.100315
    23    0.494392    -1.982058    -0.384783    -0.372455
    24    1.215364    1.043641    0.624550    0.467968
    25    0.215523    0.312841    -0.060308    -0.875984
    26    -1.135017    -0.063532    0.319131    -0.700542
    27    0.183737    -0.076965    -0.014999    0.711829
    28    1.348638    0.812489    0.489820    1.207570
    29    -2.435077    -0.858729    -0.942066    0.732689
    30    0.791332    -1.089636    -0.453003    -0.630916
    31    0.071361    0.029469    0.051310    0.473051
    32    -0.814295    0.398640    -0.185814    -0.774485
    33    0.578655    -1.780421    1.203517    0.166697
    34    0.430287    -0.916687    1.447872    -0.166584
    35    -0.142278    -0.033319    -0.503827    1.685162
    36    0.267174    -0.660718    0.592760    -1.999655
    37    -0.008522    1.281695    -0.247696    -0.792215
    38    1.461348    -0.716580    0.748531    -0.948239
    39    -0.627528    1.069450    -0.598248    0.544610
    40    -0.079064    1.758644    1.057895    0.532964
    41    -0.104020    0.659945    -0.109066    -1.724713
    42    -0.501239    -1.516701    1.095822    1.801034
    43    0.076188    -1.364045    0.142956    -0.062114
    44    -0.450091    1.413097    0.594281    -0.867741
    45    -0.617244    1.112824    -0.484753    -0.348894
    46    0.736782    -0.601504    0.917616    0.387469
    47    -0.921364    0.194857    0.965232    0.006958
    48    -0.568531    -1.979506    0.965640    -0.617862
    49    -0.161154    -0.278164    0.236000    -0.181289
    [24]
    
    
    
    df.plot.scatter(x='A',y='B')
    <matplotlib.axes._subplots.AxesSubplot at 0x24f003b98d0>
    
    [31]
    
    
    
    # 散点图
    df = pd.DataFrame(3*np.random.rand(4),index=['A','B','C','D'],columns=['aa'])
    df
    aa
    A    2.265322
    B    1.600306
    C    2.545557
    D    2.660989
    [32]
    
    
    
    df.plot.pie(subplots=True)
    array([<matplotlib.axes._subplots.AxesSubplot object at 0x0000024F0154A6D8>],
          dtype=object)
    
    [-]
  • 相关阅读:
    Unity异步加载场景loading条
    (转)Unity3D命令行Build
    (转)Unity3d UnityEditor编辑器定制和开发插件
    (转)U3D不同平台载入XML文件的方法——IOS MAC Android
    Unity3D中的欧拉角的理解
    (转)在ios android设备上使用 Protobuf (使用dll方式)
    (转)[原创]在ios android设备上使用 Protobuf (使用源码方式)
    (转)欧拉角与万向节死锁
    (转) unity 在移动平台中,文件操作路径详解
    微信小程序四(设置底部导航)
  • 原文地址:https://www.cnblogs.com/vvzhang/p/15032920.html
Copyright © 2020-2023  润新知