Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Numpy add hspace between 3D plot and 2D plot with shared axes

Attached is an image showing the current plot. I am setting fig.subplots_adjust(hspace=0) for the 2D plots to share a common x-axis. I would like to add space between the 3D and 2d plots but am not quite sure how to accomplish this as hspace is set to 0.

fig.subplots_adjust(hspace=0)
for ax in [px_t, py_t, pz_t]:
    plt.setp(ax.get_xticklabels(), visible=False)

enter image description here

like image 260
Matt Stokes Avatar asked Aug 27 '26 00:08

Matt Stokes


1 Answers

In this case, it's best to use two separate GridSpec instances. That way you can have two separate hspace parameters. Alternatively, you can manually place the top axes.

As an example of the first option:

import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

fig = plt.figure(figsize=(8, 10))
gs1 = plt.GridSpec(2, 1, hspace=0.2)
gs2 = plt.GridSpec(8, 1, hspace=0)

ax1 = fig.add_subplot(gs1[0], projection='3d')
ax1.plot(range(10), range(10), range(10))

ax = fig.add_subplot(gs2[4])
lower_axes = [ax]
for i in range(4, 8):
    if i > 4:
        ax = fig.add_subplot(gs2[i], sharex=lower_axes[0])
    ax.plot(range(10))
    ax.locator_params(axis='y', nbins=5, prune='both')
    lower_axes.append(ax)

for ax in lower_axes:
    ax.label_outer()

plt.show()

enter image description here

like image 178
Joe Kington Avatar answered Aug 28 '26 14:08

Joe Kington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!