1

I'm plotting sequential images of a dot going round in a circle. I'm trying to output square images using plt.savefig(). The default output has dimensions 640 × 480 (not square).

Using figure(figsize = (x_size,y_size)), I can specify the number of inches along each dimension in the output of plt.savefig(), as discussed in How do I change the size of figures drawn with Matplotlib?. However this centres the image so that my dot always appears in the centre of the frame.

To be more clear, using the following code I can output square images (500 × 500) of dot going round in circle :

for i in range(N):
  x = np.cos(w * t)
  y = np.sin(w * t)
  t += dt
  plt.xlim(-2, 2)
  plt.ylim(-2, 2)
  fig = plt.figure(figsize=(5, 5))
  plt.scatter(x, y, marker='o', c='black', s=100)
  plt.axis('off')
  plt.savefig("./fig" + str(i) + ".png")

However, the image is shifted along the x, y axis such that the dot always appears in the centre of the image.

How can I output square images without centering the image?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
J Physics
  • 11
  • 2
  • The size of the figure is independent of the position of the dot. Hence it's not clear what you're asking about. Best show a [mcve] of the problem at hand such that people can help you. – ImportanceOfBeingErnest Jan 27 '19 at 10:25

1 Answers1

0

Define fig = plt.figure(figsize=(5, 5)) before setting plt.xlim(-2, 2) and plt.ylim(-2, 2).


This answer was posted as an edit to the question How to change size of figures drawn in matplotlib without centering? by the OP J Physics under CC BY-SA 4.0.

vvvvv
  • 25,404
  • 19
  • 49
  • 81