I have a set of 100 random 2D points (between 0 and 20) in a scatter plot with 2 sub plots surrounding the main. When I zoom in the main scatter plot, the range on the subplots gets shrunk, however I can see points from outside the zoom window region.
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import random
numPoints = 100
x = [random.uniform(0, 20) for i in range(numPoints)]
y = [random.uniform(0, 20) for i in range(numPoints)]
# Set up the axes with gridspec
fig = plt.figure(figsize=(6, 6), constrained_layout=True)
grid = fig.add_gridspec(ncols=2, nrows=2, width_ratios=[0.3, 5], height_ratios=[5, 0.3])
main_ax = fig.add_subplot(grid[:-1, 1:])
main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)
y_hist = fig.add_subplot(grid[:-1, 0], xticklabels=[], sharey=main_ax)
x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)
x_hist.plot(
x, [0 for i in x],
'ok',
color='gray'
)
x_hist.invert_yaxis()
y_hist.plot(
[0 for i in y], y,
'ok',
color='gray'
)
y_hist.invert_xaxis()
main_ax.grid(True, lw = 1, ls = '--', c = '.75')
x_hist.grid(True, axis="x", lw = 1, ls = '--', c = '.75')
y_hist.grid(True, axis="y", lw = 1, ls = '--', c = '.75')
plt.show()
I am trying to get the dots in the left and bottom sub plots of the above image to match just what you see in the main plot (3 points).
Instead they show everything in that direction. The Left subplot shows every point on the x axis between 0 and 2.5. The bottom subplot shows every point on the y axis between 10 and 12.5.