我想把标签放在情节上。我的代码就像
import matplotlib.pyplot as plt
x1 = [1,2,3,4,5,6,7,8,9,10]
x2 = [7,3,2,4,1,4,3,5,8,4]
y = [0,1,1,0,1,0,0,1,0,1]
plt.scatter(x1,x2,c=y)
plt.show()
输出:
我想在图表上添加图例标签 0 和 1 。如果标签是假的还是真的,它的好处是什么?
如果答案没有任何迭代,我们将不胜感激
答案 0 :(得分:0)
原则上,matplotlib scatterplot with legend或Matplotlib scatter plot with legend等问题会显示如何获取散点图的图例。
由于您明确要求不进行迭代,您当然可以通过映射替换迭代。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://use.fontawesome.com/7743338bf9.js"></script>
<link href="https://fonts.googleapis.com/css?family=Heebo" rel="stylesheet">
<link rel="stylesheet" href="static/normalize.css">
<link rel="stylesheet" href="static/skeleton.css">
<link rel="stylesheet" href="static/main.css">
<link rel="icon" href="static/assets/favicon.png">
</head>
<body>
<div class="hero center-text">
<div class="container">
<section class="intro twelve columns">
<div class="row">
<h2>projects</h2>
<div class="row">
<div class="one-half column" id="project-break">
<div class="tile u-max-full-width pomodoro">
<div class="text center-text">
<h1>Pomodoro</h1>
<p class="animate-text">
Pomodoro is a productivity oriented web application which incentivizes the<br><a href="https://en.wikipedia.org/wiki/Pomodoro_Technique" target="_blank">Pomodoro Technique</a>.
</p>
<p class="animate-text">
Built with: Django/Python, HTML5, CSS, JavaScript, jQuery, and AJAX.
</p>
</div>
<a href="#" target="_blank"><i class="fa fa-github fa-project animate-text fa-fade" aria-hidden="true"></i></a>
</div>
</div>
<div class="one-half column" id="project-break">
<div class="tile u-max-full-width duelr">
<div class="text center-text">
<h1>Duelr</h1>
<p class="animate-text">
An online multiplayer 1v1 fighting game.
</p>
<p class="animate-text">
Built with: JavaScript, Node.js, Express.js, Socket.io, HTML5, CSS, and Phaser.
</p>
</div>
<a href="#" target="_blank"><i class="fa fa-github fa-project animate-text fa-fade" aria-hidden="true"></i></a>
</div>
</div>
</div>
<div class="row">
<div class="twelve columns">
<div class="tile u-max-full-width center grt-bot">
<div class="text center-text">
<h1>GRT Messenger Bot</h1>
<p class="animate-text">
The Grand River Transit Bot is a service published on Facebook Messenger which yields real-time bus information to users through HTTP requests.
</p>
<p class="animate-text">
Built with: JavaScript, Node.js, Express.js, and API.ai.
</p>
</div>
<a href="#" target="_blank"><i class="fa fa-github fa-project animate-text fa-fade" aria-hidden="true"></i></a>
</div>
</div>
</div>
</div>
<div class="row">
<h2>contact</h2>
</div>
</div>
</div>
<script src="static/app.js"></script>
</body>
</html>
请注意,这是一个纯粹的学术示例,使用for循环要容易得多。