Adjust the distance only between two subplots in matplotlib

2024/9/29 1:27:37

I have 3 subplots (3 rows and 1 column). We can use fig.subplots_adjust(hspace=0.2) to adjust the distance between the subplots. this will change the distance between subplots for all case. How can I have different distance between plot 1 (311) & plot 2 (312), and plot 2 (312) & plot 3 (313)?

Answer

Good question. Try this:

from mpl_toolkits.axes_grid1 import make_axes_locatable ax1 = plt.subplot2grid((1,1), (0,0))
divider = make_axes_locatable(ax1) 
ax2 = divider.append_axes("bottom", size="100%", pad=0.5)
ax3 = divider.append_axes("bottom", size="100%", pad=1)

Then you would get:

enter image description here

https://en.xdnf.cn/q/71270.html

Related Q&A

Many-to-many multi-database join with Flask-SQLAlchemy

Im trying to make this many-to-many join work with Flask-SQLAlchemy and two MySQL databases, and its very close except its using the wrong database for the join table. Heres the basics... Ive got main_…

Merge two rows in the same Dataframe if their index is the same?

I have created a large Dataframe by pulling data from an Azure database. The construction of the dataframe wasnt simple as I had to do it in parts, using the concat function to add new columns to the d…

How do I use the Postgresql ANY operator in a NOT IN statement

Using Pyscopg2, how do I pass a Python list into an SQL statement using the ANY Operator?Normal Working SQL reads (See SQL Fiddle):SELECT * FROM student WHERE id NOT IN (3);Using Psycopg2 as below:Psy…

pass command-line arguments to runpy

I have two files, one which has a side effect I care about that occurs within the if __name__ == "__main__" guard:# a.py d = {} if __name__ == "__main__":d[arg] = helloThe second fi…

Altering my python path: helloworld.py returns command not found—

Massive apologies for this embarrassing question—Im using my MacBook Pro, running snow leopard, and using Python 2.7.1. Trying to run my first script and all the first pages of all my tutorials are la…

ImportError: cannot import name force_text

I have installed Python 2.7 and Django 1.4 in my CentOS machine and installed all dependencies for my existing project. When I run python manage.py runserver, I am getting the following traceback in my…

How can I select the pixels that fall within a contour in an image represented by a numpy array?

VI have a set of contour points drawn on an image which is stored as a 2D numpy array. The contours are represented by 2 numpy arrays of float values for x and y coordinates each. These coordinates are…

Get the value of specific JSON element in Python

Im new to Python and JSON, so Im sorry if I sound clueless. Im getting the following result from the Google Translate API and want to parse out the value of "translatedText":{"data"…

How does setuptools decide which files to keep for sdist/bdist?

Im working on a Python package that uses namespace_packages and find_packages() like so in setup.py:from setuptools import setup, find_packages setup(name="package",version="1.3.3.7"…

How to implement multivariate linear stochastic gradient descent algorithm in tensorflow?

I started with simple implementation of single variable linear gradient descent but dont know to extend it to multivariate stochastic gradient descent algorithm ?Single variable linear regression impo…