当前位置:网站首页>(完美解决)matplotlib图例(legend)如何自由设置其位置
(完美解决)matplotlib图例(legend)如何自由设置其位置
2022-07-03 05:07:00 【音程】
前言
plt.legend()
我们知道,这一条代码会帮我们显示图例,而且通常,其会放置在图片中一个不错的位置。但是如果我们的数据,占满了整个图像,此时,其放的位置就会出问题了。
那么我们该如何自由设置图例位置呢?
loc
这个参数内置了一些位置,如果这些位置恰好有你想要的,那么用这个就行了,很方便。

plt.legend(loc=1)#这个就等价于将图例放置在右上角的位置。
bbox_to_anchor
这个是绝招,因为其可以控制任意位置。
plt.legend(bbox_to_anchor=(1,0))
这个玩意是一个坐标,原点就是图的左下角。但是,这个坐标的数值表示的是比例。比如
(1,0)#右下角
(0,1)#左上角
(0.5,0.5)#中间
(0.4,0.4)#中间往左下一点,哈哈。
所以说,很简单了,你自己慢慢调到你想要的位置就行了。注意,上面还支持负数哦。

最终,成功调节到了一个中间,偏左的位置哈哈。
吃水不忘挖井人,学习自https://www.freesion.com/article/239347665/
边栏推荐
- My first Smartphone
- Go language interface learning notes
- Thesis reading_ Tsinghua Ernie
- Kept hot standby and haproxy
- Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
- Learn to use the idea breakpoint debugging tool
- Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
- Based on RFC 3986 (unified resource descriptor (URI): general syntax)
- [basic grammar] C language uses for loop to print Pentagram
- [research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
猜你喜欢

JQ style, element operation, effect, filtering method and transformation, event object

The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article

MPM model and ab pressure test

leetcode406. Rebuild the queue based on height

leetcode452. Detonate the balloon with the minimum number of arrows

cookie session jwt

appium1.22. Appium inspector after X version needs to be installed separately

Learn to use the idea breakpoint debugging tool

Thesis reading_ Chinese NLP_ ELECTRA

RT thread flow notes I startup, schedule, thread
随机推荐
Audio Focus Series: write a demo to understand audio focus and audiomananger
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
Webapidom get page elements
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
Notes | numpy-07 Slice and index
Ueditor, FCKeditor, kindeditor editor vulnerability
@RequestMapping
1099 build a binary search tree (30 points)
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
leetcode435. Non overlapping interval
cookie session jwt
The 19th Zhejiang I. barbecue
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
Overview of basic knowledge of C language
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
Notes | numpy-08 Advanced index
String matching: find a substring in a string
最大连续子段和(动态规划,递归,递推)