Python matplotlib绘图设置图例
一、语法简介
plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10)
#edgecolor 图例边框线颜色 facecolor 图例背景色 shadow 是否添加阴影 title 图例标题 fontsize 设置字体大小
'''
设置图例位置loc参数简介
best 0 根据图标区域自动选择最合适的位置
upper right 1 右上角
upper left 2 左上角
lower left 3 左下角
lower right 4 右下角
right 5 右侧
center left 6 左侧中心
center right 7 右侧中心
lower center 8 底部中心
upper center 9 顶部中心
center 10 正中心位置
'''
二、完整代码
import matplotlib.pyplot as plt
import numpy as np plt.rcParams['font.sans-serif'] = ['STZhongsong'] # 指定默认字体:解决plot不能显示中文问题
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号 x=np.arange(8)
y=np.arange(100,900,100) print(y)
#建立画布 figsize,它用width和height来控制画布的宽和高
plt.figure(figsize=(8,6),dpi=90) #facecolor='red'设置画布颜色 plt.subplot(1,1,1)#建立坐标系
plt.bar(x,y,label='销售数量') #绘制柱状图 plt.xlabel("销售月份",fontsize=10,color='red',fontweight='bold',loc='center',backgroundcolor='black',labelpad=6)
#显示横坐标标题 fontsize设置字体大小,color设置字的颜色,fontweight设置标签是否加粗
#loc设置标签位置(具体值有center left right) backgroundcolor设置标签的背景颜色 labelpad与轴的距离
plt.ylabel("销售数量") plt.xticks(x,['2021年1月','2021年2月','2021年3月','2021年4月','2021年5月','2021年6月','2021年7月','2021年8月',],rotation=15)
plt.yticks(y,['100k','200k','300k','400k','500k','600k','700k','800k',],
rotation=30,fontsize=10,color='red',fontweight='bold',backgroundcolor='black')#rotation设置刻度值倾斜角度 plt.xlim(-1,9) #设置x轴刻度值的范围
plt.ylim(0,900)#设置y轴刻度值的范围
plt.axis("on")
#plt.axis("off") #关闭坐标轴 plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10)
#edgecolor 图例边框线颜色 facecolor 图例背景色 shadow 是否添加阴影 title 图例标题 fontsize 设置字体大小
'''
设置图例位置loc参数简介
best 0 根据图标区域自动选择最合适的位置
upper right 1 右上角
upper left 2 左上角
lower left 3 左下角
lower right 4 右下角
right 5 右侧
center left 6 左侧中心
center right 7 右侧中心
lower center 8 底部中心
upper center 9 顶部中心
center 10 正中心位置
'''
plt.show()
三、效果图展示
Python matplotlib绘图设置图例的更多相关文章
- Python matplotlib绘图设置坐标轴的标题
一.语法简介 plt.xlabel("销售月份",fontsize=16,color='red',fontweight='bold',loc='center',background ...
- 【划重点】Python matplotlib绘图设置坐标轴的刻度
一.语法简介 plt.xticks(ticks,labels,rotation=30,fontsize=10,color='red',fontweight='bold',backgroundcolor ...
- python matplotlib 绘图基础
在利用Python做数据分析时,探索数据以及结果展现上图表的应用是不可或缺的. 在Python中通常情况下都是用matplotlib模块进行图表制作. 先理下,matplotlib的结构原理: mat ...
- Python Matplotlib绘图基础
Matplotlib绘图基础 1.Figure和Subplot import numpy as np import matplotlib.pyplot as plt #创建一个Figure fig = ...
- Python matplotlib绘图学习笔记
测试环境: Jupyter QtConsole 4.2.1Python 3.6.1 1. 基本画线: 以下得出红蓝绿三色的点 import numpy as npimport matplotlib. ...
- python matplotlib绘图
import numpy as np import matplotlib.pyplot as plt from scipy.constants.constants import alpha from ...
- 【划重点】Python matplotlib绘图建立画布和坐标系
一.建立画布 import matplotlib.pyplot as plt import numpy as np x=np.arange(8) y=np.arange(8) print(x,y) # ...
- python matplotlib绘图大全(散点图、柱状图、饼图、极坐标图、热量图、三维图以及热图)
//2019.7.14晚matplotlib七种常见图像输出编程大全 七种图形汇总输出如下: import numpy as np #导入数据结构nmupy模块import matplotlib.py ...
- python matplotlib 绘图
饼图 import matplotlib.pyplot as plt # The slices will be ordered and plotted counter-clockwise. label ...
随机推荐
- 菜鸡的Java笔记 数字操作类
数字操作类 Math 类的使用 Random 类的使用 BigInteger 和 BigDecimal 类的使用 Math 是一 ...
- 从华为新发布的WeAutomate 3.0,看RPA如何在政企领域落地生长
文/王吉伟 11月11日,是电商的重要节日.即便今年双11的气氛不如往年浓烈,人们依旧关注双11厂商战报,关注购物车里的商品有没有降价. 当然在RPA领域,大家除了关注双11的商品价格,更关注华为RP ...
- [hdu5629]Clarke and tree
首先由一个神奇的序列叫做Purfer序列,他可以表示一棵树,且每个节点出现此时为度数-1(因此总长为n-2). 然后dp,用f[i][j][k]表示用前i个点中的j个点构成了一个长度为k的Purfer ...
- TCP、三次握手、四次挥手(图解)
传输控制协议(TCP,Transmission Control Protocol)是一种面向连接的.可靠的.基于字节流的传输层通信协议,为了在不可靠的互联网络上提供可靠的端到端字节流而专门设计的一个传 ...
- 发布项目到maven中央仓库
https://www.xiaominfo.com/2017/04/25/swagger-bootstrap-ui-issue-maven-central/?tdsourcetag=s_pcqq_ai ...
- [LCT学习时的一些笔记]
会找时间写一篇学习笔记的. \(Access\)的操作是把\(x\)和\(x\)所在原树的顶端点的路径变为一个\(splay\) 对于原树边我们有这样的操作,对每个\(splay\)的顶点维护一个父亲 ...
- 洛谷 P6383 -『MdOI R2』Resurrection(DP)
洛谷题面传送门 高速公路上正是补 blog 的时候,难道不是吗/doge,难不成逆在高速公路上写题/jy 首先形成的图显然是连通图并且有 \(n-1\) 条边.故形成的图是一棵树. 我们考虑什么样的树 ...
- 洛谷 P4240 - 毒瘤之神的考验(数论+复杂度平衡)
洛谷题面传送门 先扯些别的. 2021 年 7 月的某一天,我和 ycx 对话: tzc:你做过哪些名字里带"毒瘤"的题目,我做过一道名副其实的毒瘤题就叫毒瘤,是个虚树+dp yc ...
- Codeforces 590E - Birthday(AC 自动机+Dilworth 定理+二分图匹配)
题面传送门 AC 自动机有时只是辅助建图的工具,真的 首先看到多串问题,果断建出 AC 自动机.设 \(m=\sum|s_i|\). 不难发现子串的包含关系构成了一个偏序集,于是我们考虑转化为图论,若 ...
- DirectX12 3D 游戏开发与实战第九章内容(上)
仅供个人学习使用,请勿转载. 9.纹理贴图 学习目标: 学习如何将局部纹理映射到网格三角形上 探究如何创建和启用纹理 学会如何通过纹理过滤来创建更加平滑的图像 探索如何使用寻址模式来进行多次纹理贴图 ...