Dear matplotlib users and developers,

I'm using `plt.draw()` to force the rendering of all artists and then,
based on their newly calculated positions, place a text label on the figure
window in figure coordinates.

The goal is to add a text label near the conventional y-axis, at the top,
right-aligned. Example code that demonstrates the problem:

```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
print(mpl.__version__)

x = np.linspace(0, 50)
y = 4*np.sin(x) + 5

fig = plt.figure(figsize=(18,9.8))
ax = fig.add_axes((0.1, 0.1, 0.8, 0.8),
    frameon=True,
    aspect='equal',
    adjustable='box',
    xlim=(x.min(), x.max()),
    ylim=(0, 10),
    xticks=[x.min(), x.max()],
    yticks=[0, 10],
    xlabel='dimension (unit)')
ax.plot(x, y)
plt.draw()  # force redraw

ylabel_pos =
fig.transFigure.inverted().transform_point(ax.transAxes.transform_point((0,1)))
label1 = fig.text(ylabel_pos[0], ylabel_pos[1], "label1", ha="right",
va="bottom")
plt.savefig('/tmp/test_pre_mpl_v_{}.png'.format(mpl.__version__))
ylabel_pos =
fig.transFigure.inverted().transform_point(ax.transAxes.transform_point((0,1)))
label2 = fig.text(ylabel_pos[0], ylabel_pos[1], "label2", ha="right",
va="bottom")
plt.savefig('/tmp/test_post_mpl_v_{}.png'.format(mpl.__version__))
```

The code shows that in mpl 1.4.3 both label1 and label2 end up at the same
(desired) position. However, mpl 1.5.0 and 1.5.1 (just installed to check)
show that label1 is at a height of 0.9 in the figure coordinates. After the
first call to `savefig`, the figure is rendered with the axes getting a new
height and width (due to the call to `aspect='equal', adjustable='box'`)
and so the subsequent call to `savefig` renders label2 in the correct
position.

Using `ax.text(x=0, y=1, s='label', transform=ax.transAxes, ha="right",
va="bottom")` gets the job done alright (both in 1.4.3, as well as 1.5.0),
but the call to `fig.text` using the subsequent transforms should have
worked, I believe.

Kind regards,

Oliver
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to