|NO.Z.00051|——————————|BigDataEnd|——|Hadoop&Python.v15|——|Arithmetic.v15|Pandas数据分析库:Pandas数据可视化|

一、数据可视化
### --- 数据可视化
~~~     pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple

import numpy as np
import pandas as pd

~~~     # 1、线形图
df1 = pd.DataFrame(data = np.random.randn(1000,4),
                   index = pd.date_range(start = '27/6/2012',periods=1000),
                   columns=list('ABCD'))
df1.cumsum().plot()

~~~     # 2、条形图
df2 = pd.DataFrame(data = np.random.rand(10,4),
                   columns = list('ABCD'))
df2.plot.bar(stacked = True)                                    # stacked 是否堆叠

~~~     # 3、饼图
df3 = pd.DataFrame(data = np.random.rand(4,2),
                   index = list('ABCD'),
                   columns=['One','Two'])
df3.plot.pie(subplots = True,figsize = (8,8))

~~~     # 4、散点图
df4 = pd.DataFrame(np.random.rand(50, 4), columns=list('ABCD'))
df4.plot.scatter(x='A', y='B')                                  # A和B关系绘制
~~~     # 在⼀张图中绘制AC散点图,同时绘制BD散点图
ax = df4.plot.scatter(x='A', y='C', color='DarkBlue', label='Group 1');
df4.plot.scatter(x='B', y='D', color='DarkGreen', label='Group 2', ax=ax)
~~~     # ⽓泡图,散点有⼤⼩之分
df4.plot.scatter(x='A',y='B',s = df4['C']*200)

~~~     # 5、⾯积图
df5 = pd.DataFrame(data = np.random.rand(10, 4),
                   columns=list('ABCD'))
df5.plot.area(stacked = True);                                  # stacked 是否堆叠
~~~     # 6、箱式图
df6 = pd.DataFrame(data = np.random.rand(10, 5),
                   columns=list('ABCDE'))
df6.plot.box()

~~~     # 7、直⽅图
df7 = pd.DataFrame({'A': np.random.randn(1000) + 1, 'B': np.random.randn(1000),
                    'C': np.random.randn(1000) - 1})
df7.plot.hist(alpha=0.5)                                        # 带透明度直⽅图
df7.plot.hist(stacked = True)                                   # 堆叠图
df7.hist(figsize = (8,8))                                       # ⼦视图绘制

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(8)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示