标题中的英文首字母大写比较规范,但在python实际使用中均为小写。
1.利用pandas进行数据分析+matplot进行可视化
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data = np.random.rand(10,4)
df = pd.DataFrame(data,columns = list("ABCD"),index=np.arange(0,100,10))
df.plot()
plt.show()
上面一段代码的运行结果如下图所示:
![img_404f440d63257704e94bd0455416e705.png](https://yqfile.alicdn.com/img_404f440d63257704e94bd0455416e705.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
2.
fig, axes = plt.subplots(2,1)
data = pd.Series(np.random.randn(16),index=list("abcdefghijklmnop"))
data.plot(kind='bar', ax=axes[0], color='k',alpha=0.7)
data.plot(kind='barh', ax=axes[1], color='r', alpha=0.7)
plt.show()
上面一段代码的运行结果如下图所示:
![img_f565f31a411ffdcec049799b36b2386f.png](https://yqfile.alicdn.com/img_f565f31a411ffdcec049799b36b2386f.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
3.折线图
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
var = df.groupby('BMI').Sales.sum()
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlabel('BMI')
ax.set_ylabel('Sum of Sales')
ax.set_title('BMI while Sum of Sales')
var.plot(kind='line')
plt.show()
上面一段代码的运行结果如下图所示:
![img_01c5492ff1b5274b9f6b12e403698a3b.png](https://yqfile.alicdn.com/img_01c5492ff1b5274b9f6b12e403698a3b.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
4.条形图
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
上面一段代码的运行结果如下图所示:
![img_44dae96a3ad020769a34bf5f78786d41.png](https://yqfile.alicdn.com/img_44dae96a3ad020769a34bf5f78786d41.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
5.柱状堆积图
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
var = df.groupby(["BMI","Gender"]).Sales.sum()
var.unstack().plot(kind='bar',stacked=True,color=['red','blue'])
plt.show()
上面一段代码的运行结果如下:
![img_46ba58069894f99166688e5913b25ad6.png](https://yqfile.alicdn.com/img_46ba58069894f99166688e5913b25ad6.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
6.绘制散点图
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(df['Age'],df['Sales'])
plt.show()
上面一段代码的运行结果如下图所示:
![img_7337ae8e0407911d6664455b8bc9690b.png](https://yqfile.alicdn.com/img_7337ae8e0407911d6664455b8bc9690b.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
7.绘制气泡图
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(df['Age'],df['Sales'],s=df['Income'])
plt.show()
上面一段代码的运行结果如下图所示:
![img_bced5a720bfd28179d01304617165644.png](https://yqfile.alicdn.com/img_bced5a720bfd28179d01304617165644.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
8.
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_excel("pandas-matplotlib.xlsx")
var = df.groupby(['Gender']).sum().stack()
temp =var.unstack()
x_list = temp['Sales']
label_list = temp.index
plt.axis('equal')
plt.pie(x_list,labels=label_list,autopct='%1.1f%%')
plt.title('experience')
plt.show()
![img_670e6eb93149b02244b09480e33f998a.png](https://yqfile.alicdn.com/img_670e6eb93149b02244b09480e33f998a.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
2.PyEcharts画图
pip install pyecharts -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
2,1
import pyecharts as pye
bar = pye.Bar("我的第一个图表","这里是副标题")
x = ["衬衫", "羊毛衫", "雪纺衫","裤子", "高跟鞋", "袜子"]
y = [5, 20, 36, 10, 75, 90]
label = '服装'
bar.add(label,x,y)
bar.render('bar01.html')
![img_ccdd86008dc060804328b8583bfba914.png](https://yqfile.alicdn.com/img_ccdd86008dc060804328b8583bfba914.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
![img_1bc48663f461916c6c108483c69496b4.png](https://yqfile.alicdn.com/img_1bc48663f461916c6c108483c69496b4.png?x-oss-process=image/resize,w_1400/format,webp)
image.png