0

I created a scatter plot which has equal min, max, steps for both x and y axis. However the result keeps making my graph look rectangle rather than a square. How can I fix this?

'''

ax = ctrl_ra.plot.scatter(x='Control', y='Infection(Ra)', color='black', alpha=0.5)
ax2 = df_sig.plot.scatter(ax=ax, x= 'Control', y='Infection(Ra)', color='red', alpha=0.5, s=5)

#Set the x-axis and y-axis scales
ax.set_xticks(np.arange(0,21,5))
ax.set_yticks(np.arange(0,21,5))

ax2.set_xticks(np.arange(0,21,5))
ax2.set_yticks(np.arange(0,21,5))

plt.show()

'''

This is what I got when I ran my code.

enter image description here

At first I thought it was the axis scale and/or size but it wasn't so I'm not sure where to go about to fix this problem.

Any help is appreciated. Thank you.

Caroline
  • 119
  • 8
  • 1
    `ax.set_aspect('equal')`. Note that in your case, `ax2` and `ax` refer to exactly the same subplot object. [`set_aspect` docs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html), [`set_adjustable` docs](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_adjustable.html#matplotlib.axes.Axes.set_adjustable) – JohanC Dec 26 '22 at 13:13

1 Answers1

1

It is the figure size, not axes scale.

Try adding

plt.figure(figsize=(12, 12))

before plotting. Or, better, use

fig, ax = plt.subplots(figsize=(12, 12))
Lodinn
  • 462
  • 2
  • 9