The following code should display “ax” offset to the right (overlapping “ax1”) with a padding on the left (where it was originally)
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
Z = np.random.rand(6, 30)
fig, (ax, ax1) = plt.subplots(1, 2)
ax.pcolor(Z)
ax1.pcolor(Z)
chartBox = ax.get_position()
ax.set_position([chartBox.x0 + chartBox.width / 2,
chartBox.y0,
chartBox.width,
chartBox.height])
ax.set_title("Original Window")
ax1.set_title("Modified Window")
plt.show()
However in a jupyter notebook (tested on vscode and on colab) the left blank space is cut off, but when running the script in a .py file, it displays it correctly. How can I address this issue?
Context
I was iterating through some data and wanted to display multiple plots 2 by 2, on odd pairing I wanted to display the single plot centered and turned off the second empty plot. The idea was to use .subplots(nrows=1,ncols=2)
(because I had no other idea) and offset the first plot to the right using ax.set_position()
. As it turned out it did not work.