-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Description
-
matplotlib 1.5.3 (pip install)
-
python 2.7.6 (apt-get from ubuntu repository)
-
ubuntu 14.04
-
goal: compute the data coordinates of upper right corner of axes.
-
issue: the code below produces wrong answer
p_data_coords = [3.0, 3.0].
But, when the last line of code is called again from the interactive session of ipython (thus, some graphics updates probably take place), correct answer is produced:p_data_coords = [5.375, 3.] -
copies of
transAxesandtransDatareturned fromax_coords_to_data_coordsindicate that it istransDatawhich changes between the calls.
import numpy as np
import matplotlib.pyplot as plt
def show_some_data():
fig = plt.figure(figsize = (8, 3))
plt.plot(3*np.random.rand(100), 3*np.random.rand(100), 'o')
plt.axis('equal')
plt.xlim(0, 3)
plt.ylim(0, 3)
plt.show()
ax = plt.gca()
return fig, ax
def ax_coords_to_data_coords(ax, point):
t = ax.transAxes + ax.transData.inverted()
return t.transform(point), ax.transAxes.frozen(), ax.transData.frozen()
fig, ax = show_some_data()
# upper right corner of coordinates:
p_ax_coords = (1, 1)
# get its coordinates in data coord system:
p_data_coords, t_ax, t_data = ax_coords_to_data_coords(ax, p_ax_coords) Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
