Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

same code, different outputs between executions (transData weird behaviour) #3833

Closed
avances123 opened this issue Nov 22, 2014 · 1 comment
Closed

Comments

@avances123
Copy link

transData returns different outputs between two executions! this is the code to reproduce it.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import date2num
import pandas as pd


rng = pd.date_range('01-01-2014','31-12-2014', freq='H')
df = pd.DataFrame(np.random.randn(len(rng),4), index=rng)


def calcula(event):
        ax = event.canvas.figure.gca()
        print ax.transData.transform((date2num(df.index[1]),0))


fig = plt.figure(figsize=(18, 6), dpi=80)
cid = fig.canvas.mpl_connect('draw_event', calcula)
ax = fig.add_subplot(111)
ax.plot_date(x=df.index,y=df[1],fmt="r-")
ax.set_xlim(df.index[1],df.index[111])
ax.grid(True,axis="x")


#plt.show()
print "antes %s" % ax.transData.transform((date2num(df.index[1]),0))
plt.savefig("/tmp/kk.png",dpi=fig.dpi)
print "despues %s" % ax.transData.transform((date2num(df.index[1]),0))

It debugs the transData.transform in several points, the program outputs the same in all points, but if you re-run the program several times, you get different points.

Example in my computer:

---------
antes [ 180.          218.66666667]
[ 180.          218.66666667]
[ 180.          218.66666667]
[ 180.          218.66666667]
despues [ 180.          218.66666667]
---------
antes [ 180.  240.]
[ 180.  240.]
[ 180.  240.]
[ 180.  240.]
despues [ 180.  240.]
----------
antes [ 180.          261.33333333]
[ 180.          261.33333333]
[ 180.          261.33333333]
[ 180.          261.33333333]
despues [ 180.          261.33333333]
@avances123
Copy link
Author

my mistake i think, due tu random y data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant