0

I have a this Python code that saves a figure as a .png file. How can I set the distance in pixel between two ticks? For example, let's say I would like two units be equal to 100 pixel, from the answer https://stackoverflow.com/a/8998541 I know that two units are equal to 74.66666667 pixel (see last line in the code), how can I change this scale factor?

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,3,100)
y = x**2
fig,ax = plt.subplots()
ax.plot(x,y)
ax.set_aspect('equal', 'box')
fig.savefig('result.png', dpi=fig.dpi)
print(ax.transData.transform([(0,2),(2,0)])-ax.transData.transform((0,0)))

enter image description here

[[ 0.         74.66666667]
 [74.66666667  0.        ]]

I checked with Gimp the results given by axis.transData and they are correct: enter image description here

I read https://matplotlib.org/2.0.2/users/transforms_tutorial.html but I cannot find the way to solve my problem.

Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153

0 Answers0