2

I have managed to produce a scatter plot which has a scale 1:1 using the command plt.axis('equal'), but the output contains too much white space on the sides. I have been looking for a way to remove that white space, such that the figure is more rectangular, but I haven't succeeded yet. Here is my code:

import matplotlib.pyplot as plt


E = [892.255, 837.587, 1227.914, 1212.741, 1053.381]
N = [395.173, 828.072, 662.757, 115.177, 519.491]
Labels = ['J1', 'J3', 'J5', 'C']

plt.scatter(E,N)
plt.annotate('J1', xy=(E[0] - 15, N[0] + 15))
plt.annotate('J3', xy=(E[1] + 10, N[1] + 5))
plt.annotate('J5', xy=(E[2] + 10, N[2] + 5))
plt.annotate('C', xy=(E[3] + 5, N[3] + 5))
plt.annotate('V1', xy=(E[4] + 15, N[4] - 20))
plt.annotate('V2', xy=(1015, 810))

plt.annotate('102,96', xy=(850, 540), size=8.5)
plt.annotate('29,99', xy=(965,655), size=8.5)
plt.annotate('65,13', xy=(1090, 640), size=8.5)
plt.annotate('119,83', xy=(1180, 500), size=8.5)
plt.annotate('82,09', xy=(980, 370), size=8.5)

plt.plot([E[0], E[4]], [N[0], N[4]], color='k', linestyle='-', linewidth=1)
plt.plot([E[1], E[4]], [N[1], N[4]], color='k', linestyle='-', linewidth=1)
plt.plot([E[2], E[4]], [N[2], N[4]], color='k', linestyle='-', linewidth=1)
plt.plot([E[3], E[4]], [N[3], N[4]], color='k', linestyle='-', linewidth=1)
plt.plot([1011.591064, E[4]], [817.704131, N[4]], color='k', linestyle='--', linewidth=1)
plt.scatter(E[4],N[4], s=6500,facecolors='none',  color='k')


plt.grid()
plt.xlabel('E (m)')
plt.ylabel('N (m)')
#plt.ylim((100,900))
#plt.xlim((800,1250))
plt.axis('equal')
plt.axis([800, 1250, 100, 900])
plt.show()

Which produces:

output

Which is great, but it would be better if the x axis goes from 800 to 1300. Is there a way to accomplish this?

1 Answer 1

4

I believe you just want to set the "adjustable" parameter to "box" instead of the default "datalim".

Just add a line something similar to plt.gca().set(adjustable='box') near the end of your code.

Using your code above, this change yields:

enter image description here

(I also changed the x-axis limits to 800-1300 instead of 800-1250 to avoid some of the text hanging over the edge and the auto-placed ticks from being too dense.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.