可视化

这篇博客深入探讨了数据可视化的实践,通过一系列图表展示如何有效地传达复杂数据信息。从柱状图、折线图到热力图,作者详细解释了各种图表的适用场景和制作技巧。此外,还展示了如何利用可视化工具提升数据分析效率,帮助读者更好地理解数据背后的故事。
摘要由CSDN通过智能技术生成
%matplotlib inline
import pandas as pd
import numpy as np
ts = pd.Series(np.random.randn(1000),index=pd.date_range("2000/1/1",periods=1000))
ts = ts.cumsum()
ts.describe()
count    1000.000000
mean        2.404469
std         8.794434
min       -18.258983
25%        -3.691859
50%         1.319232
75%         9.123154
max        24.196742
dtype: float64
ts.plot(title="cumsum");

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sZdG2caM-1575251389503)(output_2_0.png)]

ts.plot(title="cumsum",linestyle="--",color="r");

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WVk5I7wR-1575251389504)(output_3_0.png)]

ts.plot(title="cumsum",linestyle="-",color="r");

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pbKdoXdY-1575251389504)(output_4_0.png)]

ts.plot(title="cumsum",linestyle="--",color="r",figsize=(8,6));

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Peux3AtL-1575251389504)(output_5_0.png)]

df = pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=list("ABCD"))
df = df.cumsum()
df.describe()
ABCD
count1000.0000001000.0000001000.0000001000.000000
mean22.11915614.9262779.4147534.509253
std14.34608916.00923710.0394619.378749
min-1.148053-16.072356-17.017132-15.367764
25%9.589624-2.4768223.285152-2.849600
50%16.72311023.4772629.6014504.185689
75%34.13179228.58872015.05384512.145347
max51.00927939.01386434.63450324.344564
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1da370746a0>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-R4Lie8nJ-1575251389505)(output_7_1.png)]

df.plot(subplots=True,figsize=(12,6))
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA3741BE48>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA35EF40F0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37182B70>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37143A58>], dtype=object)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cyXuiE7T-1575251389506)(output_8_1.png)]

df.plot(subplots=True,figsize=(12,6),sharey=True)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37504E80>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA375CB240>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA376340F0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x000001DA37687BA8>], dtype=object)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kGQOUPwV-1575251389506)(output_9_1.png)]

df["ID"] = np.arange(len(df))
df.describe()
ABCDID
count1000.0000001000.0000001000.0000001000.0000001000.000000
mean22.11915614.9262779.4147534.509253499.500000
std14.34608916.00923710.0394619.378749288.819436
min-1.148053-16.072356-17.017132-15.3677640.000000
25%9.589624-2.4768223.285152-2.849600249.750000
50%16.72311023.4772629.6014504.185689499.500000
75%34.13179228.58872015.05384512.145347749.250000
max51.00927939.01386434.63450324.344564999.000000
df.plot(x="ID",y=["A","C"])
<matplotlib.axes._subplots.AxesSubplot at 0x1da376c23c8>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kW6m7js4-1575251389507)(output_11_1.png)]

df = pd.DataFrame(np.random.rand(10,4),columns=["A","B","C","D"])
df
ABCD
00.4445030.6788820.7116760.872925
10.2258380.4937890.5387840.542961
20.4203300.5243190.5088460.473383
30.3319960.0919400.9940040.853556
40.8705560.0298550.7808780.644138
50.6901740.2371410.8636930.435956
60.6833660.6432390.5607690.666324
70.2902080.2166070.2586220.166087
80.4050440.4100000.1772040.408454
90.9921540.2405510.0154210.108396
df.ix[0].plot(kind="bar")
<matplotlib.axes._subplots.AxesSubplot at 0x1da379dd668>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4trCymUP-1575251389508)(output_13_1.png)]

df.plot.bar()
<matplotlib.axes._subplots.AxesSubplot at 0x1da37a1b320>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Yrn695Oj-1575251389509)(output_14_1.png)]

df.plot.bar(stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37c1e4a8>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Jdv24zZJ-1575251389509)(output_15_1.png)]

df.plot.barh(stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37d892b0>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PvXU8Jra-1575251389510)(output_16_1.png)]

df = pd.DataFrame({"a":np.random.randn(1000)+1,"b":np.random.randn(1000),
                  "c":np.random.randn(1000)-1},columns = ["a","b","c"])
df
abc
01.5085280.404443-0.534487
10.3704181.160731-0.217312
21.058697-0.027429-2.066464
31.063785-0.144785-0.923300
41.1324790.486729-0.115393
52.092360-0.752528-1.924127
60.153165-0.340198-0.233272
72.4186081.408432-0.687934
80.373591-0.418594-0.658360
92.532213-2.359132-0.368593
100.613558-1.450630-0.674410
112.3434652.872800-1.575740
12-0.189745-1.741091-2.991217
132.340176-0.419048-1.078283
141.337136-0.407258-0.567033
151.069504-0.447810-0.480902
161.232424-0.042300-2.126393
171.3703000.103638-2.782600
180.1702930.502030-1.879367
190.9354251.412264-2.285003
20-0.4733951.218304-1.218603
210.4115391.510731-0.926930
222.0171151.144694-0.870550
233.316523-0.113644-2.162518
243.876220-0.203869-0.882337
250.656042-0.068283-2.105597
260.5369140.336117-1.387146
270.6765820.070966-2.408016
282.113552-1.5400610.260771
291.893816-0.578299-2.246309
............
9701.379514-0.3213170.026253
9711.0676490.231581-3.067849
9721.8102182.071032-2.139325
9730.403939-1.042608-1.383304
9740.6442151.513606-0.905781
975-0.264936-0.190200-1.493029
9761.630804-0.107588-2.895967
9770.6522930.2627080.888875
9781.6909420.772953-0.464693
9792.511817-1.230557-2.211896
9800.450269-2.2370940.999156
9811.0013770.639334-2.622172
9821.9813271.319141-1.578372
9831.7922290.334895-0.446803
9842.5348701.592219-1.873945
9850.793888-0.424491-1.172793
9860.0199100.539585-0.293116
9870.0912860.9839001.619152
9880.4191000.439740-2.630594
989-0.4120201.299779-3.382575
9900.6134580.2927380.018183
9910.896996-1.173539-0.891172
9921.977623-1.110332-1.626624
9932.272282-0.766354-1.083257
9940.749779-0.291405-1.987565
9952.277932-0.712442-0.899629
9961.7538360.034022-1.778725
9971.154649-0.214109-0.713381
9980.9866081.141246-1.220707
9990.709445-0.386841-2.335145

1000 rows × 3 columns

df["a"].hist()
<matplotlib.axes._subplots.AxesSubplot at 0x1da37dcee48>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1N6tw8D2-1575251389512)(output_18_1.png)]

df["a"].hist(bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x1da37f56e48>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1olbl4xM-1575251389512)(output_19_1.png)]

df.plot.hist(subplots=True,sharex=True,sharey=True);

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6r6QmZSU-1575251389513)(output_20_0.png)]

df.plot.hist(subplots=True,sharex=True,sharey=True,bins=50);

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-snEPjY3u-1575251389513)(output_21_0.png)]

df.plot.hist()
<matplotlib.axes._subplots.AxesSubplot at 0x1da3960bd68>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M52C4JzX-1575251389514)(output_22_1.png)]

df.plot.hist(alpha=0.3,stacked=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1da3934e978>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-I4ezftXZ-1575251389515)(output_23_1.png)]

df["a"].plot.kde()
<matplotlib.axes._subplots.AxesSubplot at 0x1da3934ec88>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ccQEhOrh-1575251389515)(output_24_1.png)]

df.plot.kde()
<matplotlib.axes._subplots.AxesSubplot at 0x1da396c0d30>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z7fOLLUC-1575251389516)(output_25_1.png)]

df = pd.DataFrame(np.random.rand(10,4),columns=["a","b","c","d"])
df
abcd
00.0523130.7379600.0946440.203991
10.1508940.7707750.8183110.671610
20.3250810.4117340.4595320.500127
30.6179310.2001290.5188970.265602
40.5402130.7519560.8716700.617191
50.0888290.7492350.3022580.933861
60.7438850.2183090.4905080.676424
70.6669100.3083700.4263990.534198
80.4596970.9202160.5452060.976506
90.6834330.6136510.2123200.421099
df.plot.scatter(x="a",y="b");

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JZboiMT0-1575251389517)(output_27_0.png)]

s = pd.Series(3*np.random.rand(4),index=["a","b","c","d"],name="series")
s
a    0.462121
b    1.574970
c    1.784554
d    0.822887
Name: series, dtype: float64
s.plot.pie(figsize=(6,6))
<matplotlib.axes._subplots.AxesSubplot at 0x1da39bc4048>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CwNoCwZb-1575251389518)(output_29_1.png)]

s.plot.pie(figsize=(6,6),autopct="%0.2f",fontsize=20,colors=["r","g","b","c"])
<matplotlib.axes._subplots.AxesSubplot at 0x1da39f8dcc0>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TKqigI52-1575251389518)(output_30_1.png)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值