Python 数据分析可视化-Matplotlib

2023-01-08 05:19:11   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《Python 数据分析可视化-Matplotlib 》,欢迎阅读!
可视化,数据分析,Matplotlib,Python
Python 数据分析可视化--Matplotlib





import matplotlib.pyplot as plt

matplotlib.reParams[‘font,sans-serif’]=[‘SimHei’] matplotlib.reParams[‘font.family’]=’sans-serif’ matplotlib.reparams[‘axes.unicode_minus’]=False fig=plt.figure()

ax1=plt.subplot(221) ax2=plt.subplot(222) ax3=plt.subplot(223) ax4=plt.subplot(224)

plt.grid(b=None,which=’major/minor/both’,axis=’both/x/y’)

规定字体



引入可视化模块

创建画布; 画布的四个模块

固定通用语句

plt.xlabel(‘xxxxxx’) plt.ylabel(‘xxxxxx’) plt.ylim(2.5,6.5)

plt.xticks(range(9),[‘1月’,’2月’,’3月’,’4月’, ‘5月’,’6月’,’7月’,’8月’,9月’],rotation=45) plt.yticks(range(10),) plt.title(‘xxxxx’,loc=’right’)

plt.legend(loc=’best’,prop=getChineseFont()) plt.show()

plt.plot(data,label=’成绩’,color=’r’,marker=’o’,linestyle=”--,linewidth=1) 案例:多条曲线图

lineslist=plt.plot(x1,y1,x2,y2,x3,y3) plt.setp(lineslist,color=’r’)

类型 实线 虚线 线点

名称取值 solid dashed dashdot

符号取值 - -- -.’

增加图形背景

参数b:设置是否显示grid,果要显示grid,b参数设置True

参数which:设置坐标轴的分割标示线的类型

参数axis:指定绘制gird的坐标轴,取值为bothxy 规定X轴的标题 规定Y轴的标题 Y轴的数值范围

X轴的标签,

rotataion指的是标签的角度 Y轴的标签 loc显示标题的位置 增加图例;prop增加中文显 显示位置

linestyle:线的类型; linewidth:线的宽度; color:线的颜色 label:数据标签

marker:数据点的形状: 主要有‘o’和’v’

曲线图


点线 不画线

dotted None

‘:’

柱形图 水平柱状图 饼形图



plt.bar(left=[2,3,4,5],height=[228,35,81,1],bottom=2,width=1,color=’r’,

edgecolor=’b’)

plt.barh([2,3,4,5],height=[228,35,81,1],height=1.0,color=’r’,edgecolor=’b’)







plt.pie(data,labels=([‘语文’,’数学’,’英语’,’物理’]),color=([‘b’,’r’,’y’,’’,’c’]),shadow=True) plt.hist(data,bins=12)

plt.hist(data,bins=12,orientation=’horizontal’)

plt.hist(Close,range=(2.3,5.5),orientation=’vertical’,cumulative=True,

color=’r’,edgecolor=’b’)

shadow:是否显示阴影 bins:设置直方图分布图区间的个数;

orientationhorizontal显示横向直方图;vertical显示水平直方图;

cumulative:显示为True累计直方图;

直方图

箱型图 散点图

相关图correllogram

plt.boxplot(data,labels=(‘open,’high’,’low’,’close’))

plt.scatter(data-x,data-y,marker=’o’,alpha=0.3,cmap=’viridis’) # Import Dataset

df = pd.read_csv("mtcars.csv")

# Plot

plt.figure(figsize=(12,10), dpi= 80)

sns.heatmap(df.corr(), xticklabels=df.corr().columns, yticklabels=df.corr().columns, cmap='RdYlGn', center=0, annot=True)

# Decorations

plt.title('Correlogram of mtcars', fontsize=22) plt.xticks(fontsize=12) plt.yticks(fontsize=12) plt.show()

案例:

import numpy as np import pandas as pd

# Prepare Data

面积图area




本文来源:https://www.wddqxz.cn/3fa9d8a7bbf67c1cfad6195f312b3169a451eac3.html

微信扫码分享

相关推荐