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 ...
随机推荐
- Python 爬取妹子图(技术是无罪的)
... import requests from bs4 import BeautifulSoup import os import sys class mzitu(): def html(self, ...
- CTF入门学习2->Web基础了解
Web安全基础 00 Web介绍 00-00 Web本意是网,这里多指万维网(World Wide Web),是由许多互相连接的超文本系统组成的,通过互联网访问. Web是非常广泛的互联网应用,每天都 ...
- 算法题-n月后兔子数量
有一对兔子,从出生后第5个月起每个月都生一对兔子,小兔子长到第5个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? public class test3 { public stati ...
- 正则表达式&&Java文本复杂操作
正则表达式1.正则表达式的优势和用途? 一种强大而灵活的文本处理工具: 大部分编程语言 .数据库.文本编辑器.开发环境都支持正则表达式.2.正则表达式定义: 正如他的名字一样是描述了一个规则,通过这个 ...
- Mac Maven 安装及配置
一.下载 打开 Maven 官方下载页面:https://maven.apache.org/download.cgi#,点击下载链接即可开始下载: 以 Maven 3.8.4 为例,解压后可以 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- Environment Modules 简明教程
Environment Modules 简明教程 1. Modules 简介 在 Linux 超算平台上,通常会安装有不同版本的多种编译器和其他软件等,如常用的编译器有 intel 和 gnu,常用的 ...
- 日常Java测试 2021/11/14
课堂测试三 package word_show; import java.io.*;import java.util.*;import java.util.Map.Entry; public clas ...
- absurd, abundant
absurd How: absolutely, completely, clearly, faintly, manifestly, obviously, patently, quite, rather ...
- 【leetcode】451. Sort Characters By Frequency
Given a string s, sort it in decreasing order based on the frequency of the characters. The frequenc ...