ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

plt绘图

2020-12-20 17:03:51  阅读:169  来源: 互联网

标签:10 plt 20 figure color label 绘图


导入模块,设置中文和负号显示。

1 import matplotlib.pyplot as plt
2 import numpy as np
3 import pandas as pd
4 
5 plt.rcParams["font.sans-serif"] = ["Microsoft YaHei"]
6 plt.rcParams['axes.unicode_minus'] = False

一、单图

1,线型图

 1 plt.figure()
 2 
 3 x = np.arange(10)
 4 y = np.arange(10)*2
 5 
 6 plt.plot(x,marker='o',linestyle='dashed',linewidth=1,color='r',label='red')
 7 plt.plot(y,marker='s',linestyle='dashed',linewidth=1,color='b',label='blue')
 8 
 9 plt.xlim(0,10)
10 plt.ylim(0,20)
11 #plt.xticks(rotation=45)
12 plt.xlabel('日期',fontsize=20)
13 plt.ylabel('金额',fontsize=20)
14 plt.grid(True,axis='y')
15 plt.annotate('hu\nyuan',xy=(4,13),xytext=(2,15),arrowprops=dict(facecolor='blue',width=1,headwidth=6))
16 plt.legend(loc='best')
17 #plt.legend(loc='upper left')

 

2,直方图

1 plt.figure()
2 x=[1,1,4,1,5,7,3,3,5,4,9,20]
3 plt.hist(x,bins=20,rwidth=0.8,color='gray')

3,柱形图

 1 plt.figure()
 2 
 3 x=list('abcdefghi')
 4 height=[1,3,2,1,5,6,7,3,6]
 5 
 6 plt.bar(x,height,width=0.8, color='gray',label='score')
 7 plt.xlabel('student')
 8 plt.ylabel('score')
 9 plt.legend()
10 
11 plt.barh(x,height, color='gray',label='score')
12 plt.xlabel('student')
13 plt.ylabel('score')
14 plt.legend()

 

4,饼图

1 plt.figure()
2 
3 x=[0.2,0.4,0.2,0.1,0.1]
4 y=['a','b','c','d','e']
5 plt.pie(x,labels=y,autopct='%3.2f%%')

5,散点图

1 plt.figure()
2 
3 x=[1,2,3,4,5]
4 y=[2,3,4,6,8]
5 plt.scatter(x,y)
6 plt.xlim(0,10)
7 plt.ylim(0,10)

6,箱形图

1 plt.figure()
2 
3 x=[[0.1,5,10],[5,10,100]]
4 y=['a','b']
5 plt.boxplot(x,labels=y)

标签:10,plt,20,figure,color,label,绘图
来源: https://www.cnblogs.com/wizard8220/p/14164075.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有