当前位置:网站首页>(完美解决)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/
边栏推荐
- String matching: find a substring in a string
- 1095 cars on campus (30 points)
- What is UUID
- Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
- Shuttle + alluxio accelerated memory shuffle take-off
- Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
- 1087 all roads lead to Rome (30 points)
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Oracle SQL table data loss
- Go language interface learning notes Continued
猜你喜欢
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
MPM model and ab pressure test
appium1.22. Appium inspector after X version needs to be installed separately
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
Thesis reading_ Chinese NLP_ ELECTRA
String matching: find a substring in a string
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
[basic grammar] C language uses for loop to print Pentagram
随机推荐
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
50 practical applications of R language (36) - data visualization from basic to advanced
leetcode406. Rebuild the queue based on height
MPM model and ab pressure test
Gbase8s unique index and non unique index
The 19th Zhejiang I. barbecue
Silent authorization login and registration of wechat applet
Shuttle + Alluxio 加速内存Shuffle起飞
JS function algorithm interview case
"Pthread.h" not found problem encountered in compiling GCC
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
leetcode452. Detonate the balloon with the minimum number of arrows
2022-02-11 daily clock in: problem fine brush
What is UUID
Class loading mechanism (detailed explanation of the whole process)
JS scope
Market status and development prospects of the global IOT active infrared sensor industry in 2022
Market status and development prospect prediction of global neutral silicone sealant industry in 2022