当前位置:网站首页>绘制板块图层
绘制板块图层
2022-07-21 05:23:00 【花花王】
绘制板块图层1
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
import squarify
color = sns.color_palette()#无参数调用color_palette()返回默认的颜色集
# 1、读取3张表
pd.options.mode.chained_assignment = None#不允许输出报错信息
products_df = pd.read_csv("products.csv")#读取products.csv文件
aisles_df = pd.read_csv("aisles.csv")#读取aisles.csv文件
departments_df = pd.read_csv("departments.csv")#读取departments.csv文件
# 2、合并3张表
#拼接的左侧products_df对象,拼接的右侧aisles.csv对象
#how决定采用不同的合并方式,为inner时取left和right的交集显示,其余部分抛弃;
# how=‘left’时,只取left的全部数据;how= ‘right’,只取right的全部数据;
# how='outer',保留两个表的所有数据,外连接。
order_products_prior_df = pd.merge(products_df, aisles_df, on='aisle_id', how='left')
order_products_prior_df = pd.merge(order_products_prior_df, departments_df, on='department_id', how='left')
order_products_prior_df.head()#输出查看,head()里可写参数
# print(order_products_prior_df)
temp = order_products_prior_df[['product_name', 'aisle', 'department']]
# print(temp)
#3.将三张表进行融合
# 列表里的两个元素解释:series,dataframe或者是panel构成的序列lsit
# axis: 需要合并链接的轴,0是行,1是列
#reset_index()重置索引,concat()多表合并
#unique()是以 数组形式(numpy.ndarray)返回列的所有唯一值(特征的所有唯一值)
temp = pd.concat([
order_products_prior_df.groupby('department')['product_name'].nunique().rename('products_department'),
order_products_prior_df.groupby('department')['aisle'].nunique().rename('aisle_department')
], axis=1).reset_index()
temp = temp.set_index('department')#以department设置索引
temp2 = temp.sort_values(by="aisle_department", ascending=False)# by要求传入一个字符或一个字符列表指定axis的排序,ascending True or False就是升序和降序了
x = 0.
y = 0.
cmap = matplotlib.cm.viridis#使用matlablib的色彩映射
mini, maxi = temp2.products_department.min(), temp2.products_department.max()#赋予最大最小值
norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)#matplotlib.colors.Normalize类属于matplotlib.colors模块。 matplotlib.colors模块用于将颜
print(temp2)
colors = [cmap(norm(value)) for value in temp2.products_department]
colors[1] = "#FBFCFE"#设置颜色
#通过同时在两列之间循环并组合字符串,可以创建标签列表
labels = ["%s\n%d aisle num\n%d products num" % (label) for label in
zip(temp2.index, temp2.aisle_department, temp2.products_department)]
fig = plt.figure(figsize=(10, 20))#设置大小
ax = fig.add_subplot(111)#第几子图
ax = squarify.plot(temp2.aisle_department, color=colors, label=labels, ax=ax, alpha=.7, )#绘图
ax.set_xticks([0,20,40,60,80,100])#设置x轴
ax.set_yticks([0,20,40,60,80,100])#设置y轴
plt.show()
绘制板块图层2
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
import squarify
color = sns.color_palette()#无参数调用color_palette()返回默认的颜色集
# 1、读取3张表
pd.options.mode.chained_assignment = None#不允许输出报错信息
products_df = pd.read_csv("products.csv")#读取products.csv文件
aisles_df = pd.read_csv("aisles.csv")#读取aisles.csv文件
departments_df = pd.read_csv("departments.csv")#读取departments.csv文件
# 2、合并3张表
#拼接的左侧products_df对象,拼接的右侧aisles.csv对象
#how决定采用不同的合并方式,为inner时取left和right的交集显示,其余部分抛弃;
# how=‘left’时,只取left的全部数据;how= ‘right’,只取right的全部数据;
# how='outer',保留两个表的所有数据,外连接。
order_products_prior_df = pd.merge(products_df, aisles_df, on='aisle_id', how='left')
order_products_prior_df = pd.merge(order_products_prior_df, departments_df, on='department_id', how='left')
order_products_prior_df.head()#输出查看,head()里可写参数
temp = order_products_prior_df[['product_name','aisle','department']]
#3.将三张表进行融合
# 列表里的两个元素解释:series,dataframe或者是panel构成的序列lsit
# axis: 需要合并链接的轴,0是行,1是列
#reset_index()重置索引,concat()多表合并
#unique()是以 数组形式(numpy.ndarray)返回列的所有唯一值(特征的所有唯一值)
temp = pd.concat([
order_products_prior_df.groupby('department')['product_name'].nunique().rename('products_department'),
order_products_prior_df.groupby('department')['aisle'].nunique().rename('aisle_department')
], axis=1).reset_index()
temp = temp.set_index('department')#以department设置索引
temp2 = temp.sort_values(by="aisle_department", ascending=False)# by要求传入一个字符或一个字符列表指定axis的排序,ascending True or False就是升序和降序了
x = 0.
y = 0.
width = 100.
height = 100.
cmap = matplotlib.cm.viridis#使用matlablib的色彩映射
mini, maxi = temp2.products_department.min(), temp2.products_department.max()#赋予最大最小值
norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)#matplotlib.colors.Normalize类属于matplotlib.colors模块。 matplotlib.colors模块用于将颜色或数字参数转换为RGBA或RGB
colors = [cmap(norm(value)) for value in temp2.products_department]
colors[1] = "#FBFCFE"#设置颜色
#通过同时在两列之间循环并组合字符串,可以创建标签列表
labels = ["%s\n%d aisle num\n%d products num" % (label) for label in zip(temp2.index, temp2.aisle_department, temp2.products_department)]
# 画图开始
fig = plt.figure(figsize=(12, 10))#设置大小
fig.suptitle("How are aisles organized within departments", fontsize=20)
ax = fig.add_subplot(111)#第几子图
ax = squarify.plot(temp2.aisle_department, color=colors, label=labels, ax=ax, alpha=.7)#绘图
ax.set_xticks([])
ax.set_yticks([])
# color bar
# 绘制numbers of products,垂直显示
img = plt.imshow([temp2.products_department], cmap=cmap)
img.set_visible(False)
fig.colorbar(img, orientation="vertical", shrink=.96)#垂直显示
fig.text(.76, .9, "numbers of products", fontsize=14)#设置numbers of products的标签值
plt.show()
边栏推荐
- 快速查看本机公网IP的几种方法
- Ipset basic usage and save configuration
- NAT网络地址转换协议
- 1.机器学习的基础概念
- [feature learning] feature learning based on deep learning and word embedding
- 网络类型划分
- Do you want to restore the drop table in oracle? Look here [just two steps]
- Do you want to recover after deleting data in oracle? Look here [just three steps]
- OSPF序列号
- 路由中的RIP
猜你喜欢
随机推荐
Several common login debugging methods
XFS file system and ext series repair methods
After VMware turns on NAT mode / host only mode, the host cannot Ping the virtual machine
After switching users, the configuration of /etc/profile does not work
vmware workstation pro 16安装出现“setup failed to generate the ssl keys necessary to run vmware”
在vscode里配置rust时遇到error:linking with ‘x86_64-w64-mingw32-gcc‘failed:exit code:1
MATLAB读取csv文件里面既有文本又有数字的文件怎么读取。(可以不止csv文件,txt等文件都可以)
NAT network address translation protocol
OSPF and rip
Network type division
[natural language processing and text analysis] summary of text feature extraction methods. Keyword extraction method. IDF and RCF with good effect are recognized.
# QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed.: unk
RFC文档下载
【自然语言处理和文本分析】基础信息检索:签名文件技术,进阶信息检索:向量空间技术(目前主流的搜索引擎在用的技术)
一顿饭的时间,教你怎样快速使用 动态代理ip 做一个获取Steam 热销商品 的方法
主机信息采集脚本
Method of clearing cache in Windows Google browser
项目实施用到的一些命令
SQLite3 modifying column names
Redis急速入门!