I'm plotting boxplots that are positioned very far apart on the X axis. I'd like to be able to zoom in and out on this graph and have the different boxplots displayed with the same width, independent of the level of zoom.
For comparison, I'd like to achieve something similar with what happens with markers on plot() or scatter() graphs that remain the same size on screen as one zooms in and out of the graph area.
Plotting the boxplots as is displays them as narrow when zoomed out and thicker as you zoom in. Changing the value of the widths parameter when calling boxplot() naturally only changes the width of the boxes, but they still scale with the zoom level.
Here is the code snippet and resulting output.
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
# Generating random data
N = 10
y1 = np.random.randn(N)
y2 = np.random.randn(N)
y3 = np.random.randn(N)
data = [y1,y2,y3]
names = ["Near","Far","Farther"]
x_positions = [1,10,100]
fig,ax = plt.subplots()
ax.boxplot(data,positions =x_positions)
ax.set_xticklabels(names)
plt.xticks(rotation=45, ha='right')
plt.show()
Zoomed out:
Zoomed in:





