当前位置:网站首页>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
边栏推荐
- 从 CSV 文件迁移数据到 TiDB
- CISP-PTE实操练习讲解
- 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
- 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
- [research materials] 2022 China yuancosmos white paper - Download attached
- Online yaml to CSV tool
- Analysis of Top1 accuracy and top5 accuracy examples
- From monomer structure to microservice architecture, introduction to microservices
- Hcip day 16
- IOT -- interpreting the four tier architecture of the Internet of things
猜你喜欢
Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
Ruffian Heng embedded bimonthly, issue 49
Pyqt5 development tips - obtain Manhattan distance between coordinates
vulnhub hackme: 1
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
[research materials] 2022 China yuancosmos white paper - Download attached
Database basic commands
ESP系列引脚說明圖匯總
Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
随机推荐
ESP系列引脚说明图汇总
leetcode刷题 (5.31) 字符串
Wireshark grabs packets to understand its word TCP segment
leetcode刷题 (5.29) 哈希表
Migrate data from SQL files to tidb
Summary of MySQL index failure scenarios
C language custom type: struct
leetcode刷题 (5.28) 哈希表
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
Leetcode question brushing record | 203_ Remove linked list elements
Make learning pointer easier (3)
Use br to back up tidb cluster data to S3 compatible storage
LDAP Application Section (4) Jenkins Access
[untitled]
What is the use of entering the critical point? How to realize STM32 single chip microcomputer?
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
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
Sanzi chess (C language)
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
备份与恢复 CR 介绍