No handles with labels found to put in legend

2023-10-27 19:08
文章标签 found put labels legend handles

本文主要是介绍No handles with labels found to put in legend,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

错误的代码

from  matplotlib  import pyplot as plt 
from  matplotlib import font_manager
import random
yy = range(0,35,5)
y1 = [random.randint(0,35) for i in yy]
y2 = [random.randint(1,35) for i in yy]
x = range(0,35,5)
plt.plot(x,y1,color = 'r'')
plt.plot(x,y2,color = 'g')

mt_font = font_manager.FontProperties(fname = 'C:/Windows/Fonts/SIMYOU.TTF')

x_ticks = ('{}岁'.format(i) for i in x)
plt.xticks(x,x_ticks,rotation = 45,fontproperties=mt_font)
#绘制网格
plt.grid(alpha=0.4)
#添加图例,这里要显示的话要在plt.plot(x,y1,color = 'r',label = '自己')添加label

plt.legend(prop=mt_font,loc='upper right')

plt.show()

运行报错

No handles with labels found to put in legend.

 

原因是要在

plt.plot(x,y1,color = 'r',label='自己')
plt.plot(x,y2,color = 'g',label = '同事')

这两行代码中添加label要不然他不知道你添加的图例是什么

 

 

这篇关于No handles with labels found to put in legend的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/287740

相关文章

springboot报错Invalid bound statement (not found)的解决

《springboot报错Invalidboundstatement(notfound)的解决》本文主要介绍了springboot报错Invalidboundstatement(not... 目录一. 问题描述二.解决问题三. 添加配置项 四.其他的解决方案4.1 Mapper 接口与 XML 文件不匹配

Anaconda 中遇到CondaHTTPError: HTTP 404 NOT FOUND for url的问题及解决办法

最近在跑一个开源项目遇到了以下问题,查了很多资料都大(抄)同(来)小(抄)异(去)的,解决不了根本问题,费了很大的劲终于得以解决,记录如下: 1、问题及过程: (myenv) D:\Workspace\python\XXXXX>conda install python=3.6.13 Solving environment: done.....Proceed ([y]/n)? yDownloa

jenkins 插件执行shell命令时,提示“Command not found”处理方法

首先提示找不到“Command not found,可能我们第一反应是查看目标机器是否已支持该命令,不过如果相信能找到这里来的朋友估计遇到的跟我一样,其实目标机器是没有问题的通过一些远程工具执行shell命令是可以执行。奇怪的就是通过jenkinsSSH插件无法执行,经一番折腾各种搜索发现是jenkins没有加载/etc/profile导致。 【解决办法】: 需要在jenkins调用shell脚

QT 编译报错:C3861: ‘tr‘ identifier not found

问题: QT 编译报错:C3861: ‘tr’ identifier not found 原因 使用tr的地方所在的类没有继承自 QObject 类 或者在不在某一类中, 解决方案 就直接用类名引用 :QObject::tr( )

java.sql.SQLException: No data found

Java代码如下: package com.accord.utils;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import

SQLException: No Suitable Driver Found - 完美解决方法详解

🚨 SQLException: No Suitable Driver Found - 完美解决方法详解 🚨 **🚨 SQLException: No Suitable Driver Found - 完美解决方法详解 🚨****摘要 📝****引言 🎯****正文 📚****1. 问题概述 ❗****2. JDBC 驱动程序的工作原理 🔧****3. 错误的根本原因 🕵️**

the following classes could not be found android.support.v7.internal.

打开XML的界面时候显示 rendering problems: the following classes could not be found android.support.v7.internal.....。 后来发现http://stackoverflow.com/questions/33742114/the-following-classes-could-not-be-fou

Linux 挂载须知: mount 一些小问题 mount: no medium found on /dev/sr0

我属于window+VM+ubuntu的配置,有时需要把windows上的文件,挂载到虚拟机上去。然后每次使用命令的时候会出现如下的问题:                其实解决问题很简单,但是由于我自己的粗心而花费了很长的时间:    这个时候一定要确认,虚拟机的设置处是否勾选了   具体如下图所示:                 然后按照  如下的命令:   mount

ssh登录服务器报错“no matching host key type found. Their offer: ssh-rsa,ssh-dss”解决方法

这个错误表明你尝试使用 ssh 连接到远程服务器时,客户端和服务器之间没有匹配的 host key 类型。具体来说,远程服务器提供了 ssh-rsa 和 ssh-dss 类型的 host key,但你的 SSH 客户端配置可能不再支持这些较旧的算法。最近的 OpenSSH 版本默认禁用了不够安全的算法,如 ssh-rsa 和 ssh-dss。 解决方法 临时启用 ssh-rsa: 你可以在

[LeetCode] 763. Partition Labels

题:https://leetcode.com/submissions/detail/187840512/ 题目 A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at mo