当前位置:网站首页>(完美解决)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/
边栏推荐
- cookie session jwt
- leetcode452. Detonate the balloon with the minimum number of arrows
- Review the configuration of vscode to develop golang
- Messy change of mouse style in win system
- 【实战项目】自主web服务器
- Notes | numpy-09 Broadcast
- [basic grammar] C language uses for loop to print Pentagram
- leetcode406. Rebuild the queue based on height
- Promise
- Realize file download through the tag of < a > and customize the file name
猜你喜欢

Thesis reading_ Tsinghua Ernie

Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution

"Hands on deep learning" pytorch edition Chapter II exercise
![[research materials] 2021 China's game industry brand report - Download attached](/img/b7/a377b0b7c742078e2feb28ebfbca62.jpg)
[research materials] 2021 China's game industry brand report - Download attached

Review the old and know the new: Notes on Data Science

Without 50W bride price, my girlfriend was forcibly dragged away. What should I do

leetcode406. Rebuild the queue based on height

leetcode452. Detonate the balloon with the minimum number of arrows

Unity tool Luban learning notes 1

Online VR model display - 3D visual display solution
随机推荐
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Source insight garbled code solution
JS function algorithm interview case
Kept hot standby and haproxy
Oracle SQL table data loss
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Notes | numpy-08 Advanced index
String matching: find a substring in a string
Notes | numpy-10 Iterative array
Market status and development prospect prediction of the global fire hose industry in 2022
Market status and development prospect prediction of global fermentation acid industry in 2022
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
Botu uses peek and poke for IO mapping
Shell script Basics - basic grammar knowledge
1099 build a binary search tree (30 points)
"Hands on deep learning" pytorch edition Chapter II exercise