【Python学习笔记 】12.可视化库Matplotlib(下)
2018-04-04 17:54
1141 查看
3.条形图和散点图
(1).条形图
fig,ax=plt.subplots() 创建子图
ax.bar(bar_positon,bar_heights,0.3) 创建条形图,位置分别为bar_position。高度分别为bar_heights,宽度为0.3。
若把ax.bar改成ax.barh 则条形图横放,如下图。
.barh版:
(2).散点图
fig,ax=plt.subplots() fig,ax分别等于plt.subplots()返回的两个值。fig返回plt.figure()。
ax.scatter(x,y) 画出横坐标为x,纵坐标为y的散点图。
4.柱形图与盒图。
(1).柱形图
柱形图指带Bins的图。
ax.hist()指画的图带Bins结构,图中不指名bins等于多少时,图中自动分bins,range(a,b)指起始位置分别为a,b
axi.set_ylim(0,50)指设置y的区间为(0,,50)import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig=plt.figure(figsize=(5,20))
ax1=fig.add_subplot(4,1,1)
ax2=fig.add_subplot(4,1,2)
ax3=fig.add_subplot(4,1,3)
ax4=fig.add_subplot(4,1,4)
ax1.hist(norm_reviews['Fandango_Ratingvalue'],bins=20,range=(0,5))
ax1.set_title('DFR')
ax1.set_ylim(0,50)
ax2.hist(norm_reviews['RT_user_norm'],20,range=(0,5))
ax2.set_title('DRT')
ax2.set_ylim(0,50)
ax3.hist(norm_reviews['Metacritic_user_nom'],20,range=(0,5))
ax3.set_title('MUN')
ax3.set_ylim(0,50)
ax4.hist(norm_reviews['IMDB_norm'],20,range=(0,5))
ax4.set_title('IN')
ax4.set_ylim(0,50)
plt.show()
(2)盒图
盒图指提取出数据某列特征四分之一,二分之一,四分之三处的值
import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig,ax=plt.subplots()
ax.boxplot(norm_reviews[cols].values)
ax.set_xticklabels(cols,rotation=90)
ax.set_ylim(0,5)
plt.show()
画多个盒图:import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig,ax=plt.subplots()
ax.boxplot(norm_reviews[cols].values)
ax.set_xticklabels(cols,rotation=90)
ax.set_ylim(0,5)
plt.show()
(1).条形图
fig,ax=plt.subplots() 创建子图
ax.bar(bar_positon,bar_heights,0.3) 创建条形图,位置分别为bar_position。高度分别为bar_heights,宽度为0.3。
若把ax.bar改成ax.barh 则条形图横放,如下图。
.barh版:
(2).散点图
fig,ax=plt.subplots() fig,ax分别等于plt.subplots()返回的两个值。fig返回plt.figure()。
ax.scatter(x,y) 画出横坐标为x,纵坐标为y的散点图。
4.柱形图与盒图。
(1).柱形图
柱形图指带Bins的图。
ax.hist()指画的图带Bins结构,图中不指名bins等于多少时,图中自动分bins,range(a,b)指起始位置分别为a,b
axi.set_ylim(0,50)指设置y的区间为(0,,50)import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig=plt.figure(figsize=(5,20))
ax1=fig.add_subplot(4,1,1)
ax2=fig.add_subplot(4,1,2)
ax3=fig.add_subplot(4,1,3)
ax4=fig.add_subplot(4,1,4)
ax1.hist(norm_reviews['Fandango_Ratingvalue'],bins=20,range=(0,5))
ax1.set_title('DFR')
ax1.set_ylim(0,50)
ax2.hist(norm_reviews['RT_user_norm'],20,range=(0,5))
ax2.set_title('DRT')
ax2.set_ylim(0,50)
ax3.hist(norm_reviews['Metacritic_user_nom'],20,range=(0,5))
ax3.set_title('MUN')
ax3.set_ylim(0,50)
ax4.hist(norm_reviews['IMDB_norm'],20,range=(0,5))
ax4.set_title('IN')
ax4.set_ylim(0,50)
plt.show()
(2)盒图
盒图指提取出数据某列特征四分之一,二分之一,四分之三处的值
import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig,ax=plt.subplots()
ax.boxplot(norm_reviews[cols].values)
ax.set_xticklabels(cols,rotation=90)
ax.set_ylim(0,5)
plt.show()
画多个盒图:import matplotlib.pyplot as plt
import pandas as pd
from numpy import arange
reviews=pd.read_csv('fandango_scores.csv')
cols=['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
fig,ax=plt.subplots()
ax.boxplot(norm_reviews[cols].values)
ax.set_xticklabels(cols,rotation=90)
ax.set_ylim(0,5)
plt.show()
相关文章推荐
- 【Python学习笔记 】11.可视化库Matplotlib(上)
- 【python学习笔记】12:用matplotlib绘制3D函数图像
- Python学习笔记:Matplotlib绘图基础
- Python可视化学习(2):Matplotlib快速绘图基础
- python可视化-matplotlib学习2
- python 数据可视化 matplotlib学习二 : 对折线图使用颜色映射
- python数据挖掘学习笔记】十.Pandas、Matplotlib、PCA绘图实用代码补充
- python 制作图表 matplotlib - 千月的python linux 系统管理指南学习笔记(18)
- python学习笔记(1)之如何在python3.x下安装PIL、numpy以及matplotlib
- Matplotlib学习笔记之数据可视化
- 深度学习之Python的可视化包 – Matplotlib
- python数据分析学习笔记-Numpy-Matplotlib-Pandas
- python学习笔记(matplotlib下载安装)
- Python-学习笔记(三)——开发环境搭建(numpy,scipy,matplotlib)
- python 数据可视化 matplotlib学习三:生成随机漫步数据并使用matplotlib呈现
- Python学习笔记(4)--Matplotlib同时画柱状图与折线图
- python Matplotlib 学习笔记(1)
- python Matplotlib 学习笔记(2)
- 用matplotlib来画图-python学习笔记16
- Python数据可视化-matplotlib学习1