当前位置:网站首页>(完美解决)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/
边栏推荐
- Thesis reading_ Chinese NLP_ ELECTRA
- Objects. Requirenonnull method description
- Shell script -- condition judgment
- RT thread flow notes I startup, schedule, thread
- Thesis reading_ Tsinghua Ernie
- [develop wechat applet local storage with uni app]
- Self introduction and objectives
- Concurrent operation memory interaction
- Unity tool Luban learning notes 1
- Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
猜你喜欢

leetcode452. Detonate the balloon with the minimum number of arrows

Mobile terminal - uniapp development record (public request encapsulation)

Thesis reading_ Chinese NLP_ ELECTRA

Overview of basic knowledge of C language

appium1.22.x 版本後的 appium inspector 需單獨安裝

Online VR model display - 3D visual display solution

How to connect the network: Chapter 1 CSDN creation punch in

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

Do you know UVs in modeling?

Analysis of proxy usage of ES6 new feature
随机推荐
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Realize file download through the tag of < a > and customize the file name
1110 complete binary tree (25 points)
1111 online map (30 points)
Botu uses peek and poke for IO mapping
Burp suite plug-in based on actual combat uses tips
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
2022-02-12 daily clock in: problem fine brush
Audio Focus Series: write a demo to understand audio focus and audiomananger
Market status and development prospect prediction of global fermentation acid industry in 2022
Review the old and know the new: Notes on Data Science
Concurrent operation memory interaction
MySQL master-slave configuration
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
Chapter II program design of circular structure
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
Webapidom get page elements
Notes | numpy-10 Iterative array
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022