接上一篇
Python 学习笔记 数据可视化之华夫饼图简介+百分比堆积华夫饼图
(27条消息) Python 学习笔记 数据可视化之华夫饼图简介+百分比堆积华夫饼图_以舟.的博客-CSDN博客
继续完成数据可视化作业之堆积华夫饼图
import pandas as pd import numpy as np from plotnine import * from plotnine.data import mpg #堆积型 data=(np.round(pd.value_counts(mpg['class'] ),0)).astype(int) data1=data.sort_values(ascending=False) ndeep= 10 a = np.arange(1,ndeep+1,1) b = np.arange(1,np.ceil(data1.sum()/ndeep)+1,1) X,Y=np.meshgrid(a,b) df_grid =pd.DataFrame({'x':X.flatten(),'y':Y.flatten()}) category=np.repeat(data1.index,data1[:]) df_grid=df_grid.loc[np.arange(0,len(category)),:] df_grid['category']=pd.Categorical(category, categories=data1.index, ordered=False) #块状 base_plot2=(ggplot(df_grid, aes(x = 'y', y = 'x', fill = 'category')) + geom_tile(color = "white", size = 0.25) + coord_fixed(ratio = 1)+ xlab("1 square = 100")+ ylab("")+ scale_fill_brewer(type='qual',palette="Set2")+ theme(panel_background = element_blank(), legend_position = "right", figure_size = (15, 8), #修改画布长宽比例 dpi = 100)) #修改画布大小 print(base_plot2)
运行结果:
python:ggplot基本概念
1,ggplot简单介绍
python的常用可视化包:Matplotlib,基于该包的二次开发的包(Pandas,Seaborn,ggplot)
动态图的绘制:Plotly,pyecharts(可在网页中展示动态图)
ggplot读取