当前位置:网站首页>(perfect solution) how to set the position of Matplotlib legend freely
(perfect solution) how to set the position of Matplotlib legend freely
2022-07-03 05:09:00 【Interval】
List of articles
Preface
plt.legend()
We know , This code will help us display the legend , And usually , It will be placed in a good position in the picture . But if our data , It takes up the whole image , here , There will be a problem with its position .
So how can we freely set the legend position ?
loc
This parameter has some built-in positions , If these positions are exactly what you want , Then use this , Very convenient .

plt.legend(loc=1)# This is equivalent to placing the legend in the upper right corner .
bbox_to_anchor
This is a unique skill , Because it can control any position .
plt.legend(bbox_to_anchor=(1,0))
This thing is a coordinate , The origin is the lower left corner of the graph . however , The numerical value of this coordinate represents the scale . such as
(1,0)# The lower right corner
(0,1)# top left corner
(0.5,0.5)# middle
(0.4,0.4)# A little lower left in the middle , ha-ha .
So , It's easy , Just slowly adjust yourself to the position you want . Be careful , It also supports negative numbers .

Final , Successfully adjusted to a middle , Left position haha .
Never forget the digger when drawing water , Learn from https://www.freesion.com/article/239347665/
边栏推荐
- JS function algorithm interview case
- Audio Focus Series: write a demo to understand audio focus and audiomananger
- 1118 birds in forest (25 points)
- leetcode860. Lemonade change
- Unity tool Luban learning notes 1
- Shallow and first code
- Compile and decompile GCC common instructions
- [set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
- Gbase8s composite index (I)
- SSM framework integration
猜你喜欢

Introduction to deep learning (II) -- univariate linear regression

Celebrate the new year together

Shuttle + alluxio accelerated memory shuffle take-off

【实战项目】自主web服务器

Concurrent operation memory interaction

The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge

RT thread flow notes I startup, schedule, thread

Burp suite plug-in based on actual combat uses tips

Actual combat 8051 drives 8-bit nixie tube

Analysis of proxy usage of ES6 new feature
随机推荐
Redis Introduction et explication des types de données
Handler understands the record
Review the configuration of vscode to develop golang
Yolov5 network structure + code + application details | CSDN creation punch in
动态规划——相关概念,(数塔问题)
Market status and development prospect prediction of global fermentation acid industry in 2022
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
MySQL master-slave configuration
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
C language program ideas and several commonly used filters
SSM framework integration
Yolov5 model construction source code details | CSDN creation punch in
(subplots用法)matplotlib如何绘制多个子图(轴域)
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
1107 social clusters (30 points)
Promise
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
study hard and make progress every day
Introduction to deep learning (II) -- univariate linear regression