python 画图 图例自由定义方式


Posted in Python onApril 17, 2020

我就废话不多说了,还是直接看代码吧!

# -*- coding: utf-8 -*-
"""
Created on Wed Mar 7 13:10:21 2018
 
@author: su
"""
 
import numpy as np
import matplotlib.pyplot as plt 
 
n_groups = 2
 
num_list = [0.8,0.80] 
num_list1 = [0.8,0.8] 
num_list2 = [0.9,0.9] 
num_list3 = [0.9,0.9] 
fig, ax = plt.subplots()
plt.grid(True, linestyle = "-", color = "#9dbcd4", linewidth = "0.7",axis= 'y') 
ax = plt.gca()
ax.spines['top'].set_visible(False) #去掉上边框
ax.spines['right'].set_visible(False) #去掉右边框
ax.spines['bottom'].set_visible(False) #去掉上边框
ax.spines['left'].set_visible(False) #去掉右边框
ax.tick_params(axis='y',width=0,length=0)
ax.tick_params(axis='x',width=0,length=0)
index = np.arange(n_groups)
bar_width = 0.5
opacity = 1
rects1 = plt.bar(index, num_list, bar_width/4,alpha=opacity, color='#6B7C85',label='Logistic',hatch='')
rects2 = plt.bar(index + bar_width/4, num_list1, bar_width/4,alpha=opacity,color='#9dbcd4',label='SVM',hatch='/')
rects3= plt.bar(index + bar_width/2, num_list2, bar_width/4,alpha=opacity,color='#1f3d4b',label='CNN',hatch='-')
rects4= plt.bar(index + bar_width*3/4, num_list3, bar_width/4,alpha=opacity,color='#3f829d',label='LSTM',hatch=':')   
# plt.xlabel('Group')
plt.ylabel('Accuracy', fontsize=18)
# plt.title('Scores by group and gender')
plt.xticks(index - 0.3+ bar_width, ('Chinese', 'English'),fontsize =18) 
plt.yticks(fontsize =18) #change the num axis size 
plt.ylim(0.7,0.95) #The ceil 
# 设置legend
plt.legend(loc='center', bbox_to_anchor=(0.5,-0.2),ncol=4,frameon=False,shadow=False)
plt.tight_layout() 
plt.show()

python 画图 图例自由定义方式

去除边框,图例放图下面。设置横标线

以上这篇python 画图 图例自由定义方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中itertools模块用法详解
Sep 25 Python
Python语言的面相对象编程方式初步学习
Mar 12 Python
python实现飞机大战
Sep 11 Python
对numpy中的where方法嵌套使用详解
Oct 31 Python
Python3实现爬取简书首页文章标题和文章链接的方法【测试可用】
Dec 11 Python
不到20行代码用Python做一个智能聊天机器人
Apr 19 Python
Python变量访问权限控制详解
Jun 29 Python
使用Python的Turtle库绘制森林的实例
Dec 18 Python
Django数据库操作之save与update的使用
Apr 01 Python
详解pyinstaller生成exe的闪退问题解决方案
Jun 19 Python
python批量提取图片信息并保存的实现
Feb 05 Python
Python激活Anaconda环境变量的详细步骤
Jun 08 Python
关于python 的legend图例,参数使用说明
Apr 17 #Python
python 实现仿微信聊天时间格式化显示的代码
Apr 17 #Python
python matplotlib实现将图例放在图外
Apr 17 #Python
python 比较字典value的最大值的几种方法
Apr 17 #Python
Python3 selenium 实现QQ群接龙自动化功能
Apr 17 #Python
python plt可视化——打印特殊符号和制作图例代码
Apr 17 #Python
Python 多线程共享变量的实现示例
Apr 17 #Python
You might like
php !function_exists("T7FC56270E7A70FA81A5935B72EACBE29"))代码解密
2011/01/07 PHP
PHP警告Cannot use a scalar value as an array的解决方法
2012/01/11 PHP
需要注意的几个PHP漏洞小结
2012/02/05 PHP
深入php函数file_get_contents超时处理的方法详解
2013/06/03 PHP
解析CI即CodeIgniter框架在Nginx下的重写规则
2013/06/03 PHP
PHP迭代器实现斐波纳契数列的函数
2013/11/12 PHP
php验证码的制作思路和实现方法
2015/11/12 PHP
PHP实现的多文件上传类及用法示例
2016/05/06 PHP
用ADODB.Stream转换
2007/01/22 Javascript
js判断输入是否为正整数、浮点数等数字的函数代码
2010/11/17 Javascript
javascript获取当前日期时间及其它操作函数
2011/01/11 Javascript
extjs 3.31 TreeGrid实现静态页面加载json到TreeGrid里面
2013/04/02 Javascript
JavaScript实现身份证验证代码
2016/02/17 Javascript
javascript判断元素存在和判断元素存在于实时的dom中的方法
2017/01/17 Javascript
自适应布局meta标签中viewport、content、width、initial-scale、minimum-scale、maximum-scale总结
2017/08/18 Javascript
Vue2.0 axios前后端登陆拦截器(实例讲解)
2017/10/27 Javascript
一步步教会你微信小程序的登录鉴权
2018/04/09 Javascript
js打开word文档预览操作示例【不是下载】
2019/05/23 Javascript
vue中在vuex的actions中请求数据实例
2019/11/08 Javascript
JavaScript 中的无穷数(Infinity)详解
2020/02/13 Javascript
详解Python的迭代器、生成器以及相关的itertools包
2015/04/02 Python
Django框架 querySet功能解析
2019/09/04 Python
python cv2读取rtsp实时码流按时生成连续视频文件方式
2019/12/25 Python
为什么python比较流行
2020/06/19 Python
python读取excel数据绘制简单曲线图的完整步骤记录
2020/10/30 Python
英国最大的自有市场,比亚马逊便宜:Flubit
2019/03/19 全球购物
什么是Oracle的后台进程background processes?都有哪些后台进程?
2012/04/26 面试题
业务部经理岗位职责
2014/01/04 职场文书
教师演讲稿范文
2014/01/08 职场文书
淘宝中秋节活动方案
2014/01/31 职场文书
《狼》教学反思
2014/03/02 职场文书
食品安全工作方案
2014/05/07 职场文书
最美孝心少年事迹材料
2014/08/15 职场文书
国企干部对照检查材料
2014/08/22 职场文书
2014旅游局党组书记党建工作汇报材料
2014/11/02 职场文书
Nginx配置https原理及实现过程详解
2021/03/31 Servers