In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how matplotlib shares axes". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn how to share axes with matplotlib.
Preface
1. Overview
Shared axes are the x or y axes shared between several sub-images. This section focuses on how to share axes when mapping with matplotlib.
Pyplot.subplots (nrows = 1Magna Ncols = 1Magna sharex = False,sharey = False,squeeze = True,subplot_kw = none, gridspec_kw = none, * * fig_kw)
Parameters:
Nrows: number of Lin
Ncols: number of columns
Sharex: whether to share X-axis coordinates
Sharey: whether to share Y-axis coordinates
Return value: array of Figure,Axes objects
1. Sharex and sharey code example:''1. Program purpose: based on sharex and sharey to achieve (1) share x axis (2) share y axis (3) share x axis and y axis (4) adjust the distance between subgraphs 2. Version 2.1 Qingdao, Shandong, May 18, 2021, Version 1. Related modules import import numpy as npimport matplotlib.pyplot as pltplt.rcParams ['font.sans-serif'] = [' SimHei'] # normal display Chinese font plt.rcParams ['axes.unicode_minus'] = False # normal display minus sign # 2. Create cartographic data x = np.linspace (- 5 Magneto 5100) Yizumi 1 = np.sin (x) Yizhi2 = np.cos (x) Yao3 = Yao2Liao3. Drawing # 3.1 shared X-axis figure, (ax1,ax2,ax3) = plt.subplots (3jue 1, figsize= (5je 6), dpi=600, # shared x-axis sharex=True) ax1.plot (x-journal yong-1-meme-cr-blueberry' Linestyle=':') ax2.plot (xQuery yong2pas cymbals orangewaylinestylepionghorangecores') ax3.plot (xrecinct yong3meme cymbals r' Linestyle=':') # adjust the vertical distance between sub-graphics figure.subplots_adjust (hspace=0.1) ax1.set_title ('the following three images share the X axis') # in fact, it is more reasonable to add figure.subtitle () # 3.2 share Y axis # to create a new drawing figure and axes object figure, (ax1,ax2,ax3) = plt.subplots (1 Magi 3, figsize= (6 Magne2) Dpi=600, # shared y-axis sharey=True) figure.suptitle ('the Y-axis is shared in the following three pictures') ax1.plot (Xrecedicy1 retro cymbals bluetooth pedigree') ax2.plot (x-recorder 2-minus cymbals orangeforth') ax3.plot (x-recorder 3) ) # adjust the horizontal distance between sub-shapes figure.subplots_adjust (wspace=0.1) # 3.3 share both x-axis and y-axis # create a new drawing figure and axes object figure, (ax1,ax2,ax3) = plt.subplots (1meme 3, figsize= (6jue 2), dpi=600 # sharing x-axis sharex=True # shared y-axis sharey=True) x4 = np.linspace (- 10Magazine 10100) yange4 = np.cos (x4) * 2figure.suptitle ('the following three pictures share both the X-axis and Y-axis') ax1.plot (x-mag) ax3.plot (x4) ) # adjust the horizontal distance between sub-graphics figure.subplots_adjust (wspace=0.1) plt.show () instance 2import matplotlib.pyplot as pltimport numpy as npplt.rcParams ['font.sans-serif'] = [' SimHei'] plt.rcParams ['axes.unicode_minus'] = Falsex=np.linspace (0Quinnp.pipping500) y=np.sin (x) * np.exp (- x) fig,ax=plt.subplots (nrows=1,ncols=2) Sharey=True) ax1=ax [0] ax1.plot (XMagy) ax1.set_title ("line chart") ax2=ax [1] ax2.scatter (XMagy) ax2.set_title ("scatter graph") plt.suptitle ("one canvas two subgraphs, and share y coordinates") # remove the gap wspace to the horizontal distance between the two graphs Hspace is the vertical distance between two graphs fig.subplots_adjust (wspace=0) plt.show () import matplotlib.pyplot as pltimport numpy as npplt.rcParams ['font.sans-serif'] = [' SimHei'] plt.rcParams ['axes.unicode_minus'] = Falsex=np.linspace (0np.exp 2piMague 500) y=np.sin (x) * np.exp (- x) fig,ax=plt.subplots (nrows=1,ncols=1) ax.plot (xMague y) ax.set_title ("line chart") ax.scatter (x Y [:-1]) plt.suptitle ("sharing axes of a single drawing area") plt.show () Thank you for your reading The above is the content of "how matplotlib shares axes". After the study of this article, I believe you have a deeper understanding of how matplotlib shares axes, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.