当前位置:网站首页>PLT in Matplotlib tight_ layout()
PLT in Matplotlib tight_ layout()
2022-07-06 08:21:00 【It's a dream, it's you!】
Catalog
4 add plt.tight_layout() after
1 problem
(1) stay matplotlib in , Axis domain ( Including subgraphs ) The position of the is specified in standardized drawing coordinates . What may happen is , Your axis label or title ( Sometimes even scale labels ) It will exceed the graphic area , Therefore, it is truncated .
(2) When you have multiple subgraphs , You will often see labels of different axis fields stacked together .
2 resolvent
# stay plt.show() with :
plt.tight_layout()
3 Case study
3.1 Code
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib; matplotlib.use('TkAgg')
mpl.rcParams['font.sans-serif'] = ['SimHei'] # Specify default font
mpl.rcParams['axes.unicode_minus'] = False # Resolve save image is negative '-' Questions displayed as squares
plt.rcParams['savefig.facecolor'] = "0.8"
def example_plot(ax, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title', fontsize=fontsize)
plt.close('all')
plt.close('all')
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
example_plot(ax1)
example_plot(ax2)
example_plot(ax3)
example_plot(ax4)
plt.show()
3.2 result
4 add plt.tight_layout() after
4.1 Code
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib; matplotlib.use('TkAgg')
mpl.rcParams['font.sans-serif'] = ['SimHei'] # Specify default font
mpl.rcParams['axes.unicode_minus'] = False # Resolve save image is negative '-' Questions displayed as squares
plt.rcParams['savefig.facecolor'] = "0.8"
def example_plot(ax, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title', fontsize=fontsize)
plt.close('all')
plt.close('all')
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)
example_plot(ax1)
example_plot(ax2)
example_plot(ax3)
example_plot(ax4)
plt.tight_layout()
plt.show()
4.2 result
边栏推荐
- IOT -- interpreting the four tier architecture of the Internet of things
- 备份与恢复 CR 介绍
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- LDAP application (4) Jenkins access
- Grayscale upgrade tidb operator
- C语言自定义类型:结构体
- 将 NFT 设置为 ENS 个人资料头像的分步指南
- Uibehavior, a comprehensive exploration of ugui source code
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- [secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
猜你喜欢
Database basic commands
vulnhub hackme: 1
Ruffian Heng embedded bimonthly, issue 49
Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
ESP系列引脚說明圖匯總
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
C语言自定义类型:结构体
将 NFT 设置为 ENS 个人资料头像的分步指南
[research materials] 2021 China online high growth white paper - Download attached
随机推荐
IOT -- interpreting the four tier architecture of the Internet of things
使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
C language custom type: struct
Upgrade tidb operator
VMware virtualization cluster
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
Grayscale upgrade tidb operator
Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
Yyds dry goods inventory three JS source code interpretation eventdispatcher
从表中名称映射关系修改视频名称
Leetcode question brushing record | 203_ Remove linked list elements
Secure captcha (unsafe verification code) of DVWA range
JS select all and tab bar switching, simple comments
Pyqt5 development tips - obtain Manhattan distance between coordinates
[t31zl intelligent video application processor data]
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
synchronized 解决共享带来的问题
Ruffian Heng embedded bimonthly, issue 49
[research materials] 2022 China yuancosmos white paper - Download attached