当前位置:网站首页>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

边栏推荐
- Make learning pointer easier (3)
- Nft智能合约发行,盲盒,公开发售技术实战--合约篇
- Grayscale upgrade tidb operator
- 1. Color inversion, logarithmic transformation, gamma transformation source code - miniopencv from zero
- IP lab, the first weekly recheck
- C language - bit segment
- Circular reference of ES6 module
- 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
- From monomer structure to microservice architecture, introduction to microservices
- 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
猜你喜欢

Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
![[t31zl intelligent video application processor data]](/img/67/b77c1de990d9b8868f8df5e55b0227.png)
[t31zl intelligent video application processor data]
![[cloud native] teach you how to build ferry open source work order system](/img/fb/507f763791235bd00bc8201e5d7741.png)
[cloud native] teach you how to build ferry open source work order system

化不掉的钟薛高,逃不出网红产品的生命周期
![[research materials] 2021 Research Report on China's smart medical industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] 2021 Research Report on China's smart medical industry - Download attached

A Closer Look at How Fine-tuning Changes BERT

C language - bit segment
![[research materials] 2021 China online high growth white paper - Download attached](/img/51/bea6179e4fac88f8b550b4213a2bca.jpg)
[research materials] 2021 China online high growth white paper - Download attached

Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform

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
随机推荐
【T31ZL智能视频应用处理器资料】
Use Alibaba icon in uniapp
sys.argv
JS select all and tab bar switching, simple comments
你想知道的ArrayList知识都在这
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
Pyqt5 development tips - obtain Manhattan distance between coordinates
CAD ARX 获取当前的视口设置
Restore backup data on S3 compatible storage with tidb lightning
leetcode刷题 (5.28) 哈希表
flask返回文件下载
C language custom type: struct
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
CAD ARX gets the current viewport settings
Use dumping to back up tidb cluster data to S3 compatible storage
Analysis of Top1 accuracy and top5 accuracy examples
C语言 - 位段
Hcip day 16
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached