当前位置:网站首页>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
边栏推荐
- Golang DNS write casually
- 让学指针变得更简单(三)
- Char to leading 0
- On why we should program for all
- 图像融合--挑战、机遇与对策
- 远程存储访问授权
- Remote storage access authorization
- MFC 给列表控件发送左键单击、双击、以及右键单击消息
- Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
- flask返回文件下载
猜你喜欢
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
hcip--mpls
[research materials] 2021 Research Report on China's smart medical industry - Download attached
Yyds dry goods inventory three JS source code interpretation eventdispatcher
将 NFT 设置为 ENS 个人资料头像的分步指南
synchronized 解决共享带来的问题
NFT smart contract release, blind box, public offering technology practice -- contract
leetcode刷题 (5.28) 哈希表
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
Analysis of pointer and array written test questions
随机推荐
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
好用的TCP-UDP_debug工具下载和使用
Introduction to number theory (greatest common divisor, prime sieve, inverse element)
Wireshark grabs packets to understand its word TCP segment
Yyds dry goods inventory three JS source code interpretation eventdispatcher
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]
IP lab, the first weekly recheck
Analysis of pointer and array written test questions
Summary of MySQL index failure scenarios
wincc7.5下载安装教程(Win10系统)
Let the bullets fly for a while
MFC sends left click, double click, and right click messages to list controls
Chinese Remainder Theorem (Sun Tzu theorem) principle and template code
String to leading 0
1204 character deletion operation (2)
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
Pyqt5 development tips - obtain Manhattan distance between coordinates
Migrate data from a tidb cluster to another tidb cluster