树地图
老规矩,直接上代码~python
import numpy as np import matplotlib.pyplot as plt import squarify size=np.array([3.4,0.693,0.585,0.570,0.562,0.531, 0.530,0.524,0.501,0.478,0.468,0.436]) # 每一项所占大小 xingzuo=np.array(['未知','摩羯座','天秤座','双鱼座','天蝎座','金牛座', '处女座','双子座','射手座','狮子座','水瓶座','白羊座']) rate=np.array(['34%','6.93%','5.85%','5.70%','5.62%','5.31%', '5.30%','5.24%','5.01%','4.78%','4.68%','4.36%']) # 每一项所占比重 colors=['steelblue','#9999ff','red','indianred', 'green','yellow','orange'] plt.rcParams['font.sans-serif']=['KaiTi'] plt.rcParams['axes.unicode_minus']=False plot=squarify.plot(sizes=size, label=xingzuo, color=colors, value=rate, edgecolor='white', linewidth=3) plt.title('菊粉星座分布',fontdict={'fontsize':12}) plt.axis('off') plt.tick_params(top='off',right='off') plt.savefig('C:/Users/xiaoLiu/Desktop/pythoncoding/squarify.jpg') plt.show()
效果图以下好看不~接下来看看更加好看的雷达图ide
import numpy as np import matplotlib.pyplot as plt plt.subplot(111,polar=True) # polar=True至关于创建一个极坐标系 plt.rcParams['font.sans-serif']=['KaiTi'] plt.rcParams['axes.unicode_minus']=False dataLenth=5 angles=np.linspace(0,2*np.pi,dataLenth,endpoint=False) labels=['沟通能力','业务理解能力','逻辑思惟能力', '快速学习能力','工具使用能力'] data=[2,3.5,4,4.5,5] data=np.concatenate((data,[data[0]])) angles=np.concatenate((angles,[angles[0]])) plt.polar(angles,data,color='r',marker='o') plt.xticks(angles,labels) plt.title(label="某数据分析师的综合评级") plt.savefig("C:/Users/xiaoLiu/Desktop/pythoncoding/polarplot.jpg") plt.show()
效果展现
哇,真好看工具
import matplotlib.pyplot as plt import numpy as np plt.subplot(1, 1, 1) fig = plt.figure() plt.figure(figsize=(8, 6)) y1 = np.array([866, 2335, 5710, 6482, 6120, 1605, 3813, 4428, 4631]) y2 = np.array([433, 1167, 2855, 3241, 3060, 802, 1906, 2214, 2315]) plt.rcParams['font.sans-serif'] = ['KaiTi'] plt.rcParams['axes.unicode_minus'] = False x=[y1,y2] labels = ['注册人数', '激活人数'] plt.boxplot(x,labels=labels,vert=True,widths=[0.2,0.5]) plt.title("腾讯qq1-9月注册用户数", loc='center') plt.grid(False) plt.legend() plt.savefig(r"C:\Users\xiaoLiu\Desktop\keshihua\9.jpg") plt.show()
看一下效果学习
import numpy as np import matplotlib.pyplot as plt plt.subplot(1,1,1) fig=plt.figure() plt.figure(figsize=(8,6)) plt.rcParams['font.sans-serif']=['KaiTi'] plt.rcParams['axes.unicode_minus']=False labels=np.array(["东区","北区","南区","西区"]) x=np.array([8566,6482,5335,7310]) explode=[0.05,0,0,0] labeldistance=1.1 plt.pie(x,labels=labels,autopct='%.0f%%',shadow=True, explode=explode,radius=1.0,labeldistance=labeldistance) plt.title("全国各分区任务量占比",loc="center") plt.savefig(r"C:\Users\xiaoLiu\Desktop\keshihua\10.jpg") plt.show()
效果图以下
挺好看的吧~,哈哈,py大法好spa
在饼图的基础上调整wedgeprops参数便可实现圆环图
代码以下3d
import numpy as np import matplotlib.pyplot as plt plt.subplot(1,1,1) fig=plt.figure() plt.figure(figsize=(8,6)) x1=np.array([8556,5335,7310,6482]) x2=np.array([4283,2667,3655,3241]) labels=["东区","北区","南区","西区"] plt.rcParams['font.sans-serif']=['KaiTi'] plt.rcParams['axes.unicode_minus']=False plt.pie(x1,labels=labels,radius=1.0, wedgeprops=dict(width=0.3,edgecolor='w')) plt.pie(x2,radius=0.7,wedgeprops=dict(width=0.3,edgecolor='w')) plt.annotate("完成量", xy=(0.35,0.35),xytext=(0.7,0.45), arrowprops=dict(facecolor='black',arrowstyle='->')) plt.annotate("任务量", xy=(0.75,0.20),xytext=(1.1,0.2), arrowprops=dict(facecolor='black',arrowstyle='->')) plt.title("全国各分区任务量和完成量",loc="center") plt.savefig(r"C:\Users\xiaoLiu\Desktop\keshihua\11.jpg") plt.show()
效果图code
撸代码blog
import numpy as np import matplotlib.pyplot as plt import itertools plt.rcParams['font.sans-serif']=['KaiTi'] plt.rcParams['axes.unicode_minus']=False cm=np.array([[1,0.082,0.031,-0.0086], [0.082,1,-0.063,0.062], [0.031,-0.09,1,0.026], [-0.0086,0.062,0.026,1]]) cmap=plt.cm.cool plt.imshow(cm,cmap=cmap) plt.colorbar() classes=["负债率","信贷数量","年龄","家眷数量"] tick_marks=np.arange(len(classes)) plt.xticks(tick_marks,classes) plt.yticks(tick_marks,classes) for i,j in itertools.product(range(cm.shape[0]),range(cm.shape[1])): plt.text(j,i,cm[i,j],horizontalalignment="center") plt.grid(False) plt.savefig(r"C:\Users\xiaoLiu\Desktop\keshihua\12.jpg") plt.show()
怎么样!好看吧~
嘻嘻图片