Hello again. This is follow-up on this 9 month old thread (I left this
issue for a while and am now returning to it).

I upgraded to the latest stable version of Matplotlib, 1.3.1, and tested
and I am still getting the exact same confusing problem.

Now I also have a small runnable test script that demonstrates this
problem, from IDLE using Python 2.7 and Matplotlib 1.3.1.

Attached is the script.  If you run it as is, it will show a plot. Click on
the last point (which is obviously higher than the rest) and note the index
number that is printed in the IDLE prompt.  It should say "index is:
[154]".  But now zoom the plot tightly around that last point, and click on
it again.  Now it will report that the index is much smaller (depending on
how tightly you zoomed), down to "index is:  [1]".  This is the problem.

What's critical to point out is:  this only occurs with *this* data.  To
show that, go to the script and comment out the line near the end that
starts with "plt.plot(bad_final_dates," and comment in the one below it,
that starts with "plt.plot(good_final_dates,".  Run the script again, and
repeat the process above.  You'll find that zooming does not affect the
index number--which is the correct behavior.

The contains_points() function was something I got on this mailing list
from Jae-Joon some years back, and it is above my level of understanding,
and it's possible I goofed something up in there.

I'm really puzzled why one set of data doesn't have this problem and
another one does. Any suggestions for what's wrong greatly appreciated.

Thanks,
Che


On Mon, Sep 16, 2013 at 9:15 AM, Benjamin Root <ben.r...@ou.edu> wrote:

>
>
>
> On Sun, Sep 15, 2013 at 11:59 PM, C M <cmpyt...@gmail.com> wrote:
>
>> Just a follow-up on this problem...
>>
>> I've found now that the index is only off if the plot is zoomed, and in
>> the following way.  When I zoom, the first point that is visible in the
>> plot window will have index = 0, the next point will have index = 1, and so
>> forth.  If I zoom another section of the points, the indices are "reset" in
>> this same way.
>>
>> What's really bizarre is that this is only occurring on one plot.  When I
>> try to reproduce the problem on other plots (so far at least), I can't.
>>
>> Any suggestions for how to chase this down would be very welcome.
>>
>> Thanks.
>>
>>
> That is a very useful observation. I am not very familiar with the artist
> picking code, but if I have to guess, I would wonder if indices are being
> determined from a path created *after* clip_to_rect() is used internally.
> Given that you are having difficulties in reproducing this issue in other
> plots, I would suggest trying to pare down your badly behaving code as much
> as you can and post it here.  Furthermore, it would also be useful to
> determine if the issue still occurs in v1.3 or in the master branch.
>
> Cheers!
> Ben Root
>
import matplotlib.pyplot as plt
import numpy as np

def contains_points(line, mouseevent):
    line.pickradius = 5    
    # Make sure we have data to plot
    if line._invalidy or line._invalidx:
        line.recache()
        
    if len(line._xy)==0: return False,{}
    
    # Convert points to pixels
    if line._transformed_path is None:
       line._transform_path()
    path, affine = line._transformed_path.get_transformed_points_and_affine()
    path = affine.transform_path(path)
    xy = path.vertices
    xt = xy[:, 0]
    yt = xy[:, 1]

    pixels = line.figure.dpi/72. * line.pickradius

    d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
    ind, = np.nonzero(np.less_equal(d, pixels**2))

    print 'index is: ', str(ind)

    return len(ind)>0,dict(ind=ind)

bad_final_dates = [735079.1214674653, 735079.5, 735079.55647688662, 735079.60561398149, 735079.60901608795, 735079.61007837963, 735079.61141004635, 735079.61222394672, 735079.61267262732, 735079.61740547454, 735079.61793575226, 735079.61845732643, 735079.61902608792, 735079.68499270838, 735079.68542109954, 735079.68880315975, 735079.68926655094, 735079.68966354162, 735079.69596565969, 735079.701868125, 735079.70749983797, 735079.70960563654, 735079.71045478014, 735079.71102318284, 735079.71184613428, 735079.71230732638, 735079.71268356487, 735079.71303708339, 735079.71386268514, 735079.71445497684, 735079.7153444445, 735079.71684614581, 735079.7183792477, 735079.71955292823, 735079.72024780093, 735079.72192891198, 735079.72248410876, 735079.72560098383, 735079.72600572917, 735079.72638543986, 735079.72990056709, 735079.73168333329, 735079.73226472223, 735079.73661531252, 735079.74144714116, 735079.74522572919, 735079.7468240856, 735079.74791210645, 735079.97846979171, 735079.98271479167, 735079.98447646992, 735080.12350728014, 735080.14091008098, 735080.55523804401, 735080.56125733792, 735080.63896374998, 735080.64021659724, 735080.64103072917, 735080.66268849536, 735080.7048011343, 735080.79961501155, 735080.86546409724, 735080.99817599542, 735081.0204026273, 735081.02133151621, 735081.02613285882, 735081.0271783449, 735081.0335956713, 735081.04115539347, 735081.04800446762, 735081.05008083337, 735081.05534546298, 735081.05918304401, 735081.06037712959, 735081.06172269676, 735081.06712594908, 735081.08196986106, 735081.62065618054, 735081.8688092361, 735081.86910491902, 735081.86998233793, 735081.99360535876, 735081.99586380785, 735082.00806468748, 735082.0098228819, 735082.01533834497, 735082.01674383099, 735082.02936186339, 735082.02976707171, 735082.03022675926, 735082.03069490741, 735082.03097482643, 735082.03125312505, 735082.03604334488, 735082.03765619209, 735082.05257208331, 735082.100969919, 735082.1024177199, 735082.10387097218, 735082.1388320023, 735082.33333333337, 735082.53595807869, 735082.55833702546, 735082.56112760422, 735083.00588994217, 735083.007571875, 735113.50807679398, 735113.58693798608, 735114.03848809027, 735114.04119372682, 735115.5, 735119.8093059028, 735120.03856688656, 735253.07588778937, 735256.95615627314, 735258.69064364582, 735258.69268998841, 735258.69969299773, 735258.72694862273, 735259.62416826386, 735259.62484111113, 735259.7361906945, 735259.75713817135, 735259.99948642356, 735260.00099298614, 735260.00174059032, 735260.00592855329, 735260.00680168986, 735260.00748263893, 735260.00827880786, 735260.00860694447, 735260.00958392362, 735260.02752453706, 735260.06593625003, 735260.07891475689, 735260.07907957176, 735260.07935114589, 735260.62010422454, 735260.62646800932, 735260.62662517361, 735260.66605687502, 735260.67675605323, 735260.68322124996, 735260.68342049769, 735260.68355356483, 735260.68561972224, 735260.68846386578, 735269.73599923612, 735285.60832390049, 735302.07172445604, 735304.07737268519, 735304.39253472222, 735306.02329861117, 735307.09005787037, 735309.60149305558]
bad_scaled_final_durations =  [0.0019444444444444444, 1.0, 0.0011111111111111111, 0.0011111111111111111, 0.0030555555555555557, 0.00083333333333333339, 0.0011111111111111111, 0.00055555555555555556, 0.00055555555555555556, 0.0011111111111111111, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00083333333333333339, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.0027777777777777779, 0.00055555555555555556, 0.00083333333333333339, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00027777777777777778, 0.00083333333333333339, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.0036111111111111109, 0.00083333333333333339, 0.0013888888888888889, 0.00027777777777777778, 0.00083333333333333339, 0.0022222222222222222, 0.00055555555555555556, 0.0063888888888888893, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00083333333333333339, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.00083333333333333339, 0.00027777777777777778, 0.00055555555555555556, 0.00083333333333333339, 0.0016666666666666668, 0.00027777777777777778, 0.00055555555555555556, 0.0016666666666666668, 0.00055555555555555556, 0.00027777777777777778, 0.00055555555555555556, 0.00083333333333333339, 0.00083333333333333339, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.0011111111111111111, 0.00055555555555555556, 0.00055555555555555556, 0.0013888888888888889, 0.0013888888888888889, 0.00027777777777777778, 0.0036111111111111109, 0.0016666666666666668, 0.00055555555555555556, 0.00027777777777777778, 0.00027777777777777778, 0.00055555555555555556, 0.00055555555555555556, 0.0025000000000000001, 0.017500000000000002, 0.0027777777777777779, 0.00083333333333333339, 0.00055555555555555556, 0.0027777777777777779, 1.0, 0.0013888888888888889, 0.0013888888888888889, 0.046388888888888889, 0.023333333333333334, 0.0027777777777777779, 0.0011111111111111111, 0.0011111111111111111, 0.00083333333333333339, 0.0013888888888888889, 0.00083333333333333339, 0.013888888888888888, 0.0063888888888888893, 0.00083333333333333339, 0.0019444444444444444, 0.0033333333333333335, 0.0016666666666666668, 0.0019444444444444444, 0.0025000000000000001, 0.00083333333333333339, 0.0011111111111111111, 0.00055555555555555556, 0.0011111111111111111, 0.0027777777777777779, 0.0013888888888888889, 0.0011111111111111111, 0.0011111111111111111, 0.0013888888888888889, 0.0011111111111111111, 0.00083333333333333339, 0.0011111111111111111, 0.00083333333333333339, 0.00055555555555555556, 0.00055555555555555556, 0.00083333333333333339, 0.0027777777777777779, 0.00083333333333333339, 0.00083333333333333339, 0.00055555555555555556, 0.0025000000000000001, 0.008611111111111111, 0.026111111111111113, 0.013055555555555556, 0.010833333333333334, 2.338888888888889]

good_final_dates = [735200.91100878478, 735260.66809070599, 735260.72494328709, 735267.64516365738, 735267.65226159722, 735267.65314098378, 735267.65448853013, 735267.65525618056, 735267.65551268519, 735267.65738644672, 735267.66037430556, 735267.66056706023, 735267.66090157407, 735267.69119524304, 735267.69249468751, 735267.69349043979, 735267.69870418985, 735267.69949305558, 735267.69978456013, 735267.70213365741, 735267.70932038198, 735267.70977334492, 735269.55732999998, 735269.55778818286, 735269.56359839125, 735269.56456887734, 735269.73359671293, 735269.73553619208, 735269.73671972228, 735269.73826893524, 735269.74042631942, 735269.7411324305, 735269.74251543987, 735269.8409260764, 735269.84166416666, 735269.84243101848, 735269.84415988426, 735269.84612753475, 735269.84721381939, 735269.99191494216, 735269.99551050924, 735269.99615495373, 735269.99695586809, 735269.99994778936, 735270.00016650464, 735270.00032298616, 735270.01406704856, 735270.01420127309, 735270.01771825226, 735270.01884452545, 735270.01914634265, 735270.01933493058, 735270.42904791667, 735270.4424228241, 735270.44254429394, 735270.4433664236, 735270.4449150695, 735270.62896396988, 735270.63031173614, 735270.6304999768, 735279.04286091437, 735292.5]
good_scaled_final_durations = [0.066666666666666666, 0.066666666666666666, 0.066666666666666666, 0.11666666666666667, 0.066666666666666666, 0.050000000000000003, 0.050000000000000003, 0.033333333333333333, 0.033333333333333333, 0.066666666666666666, 0.050000000000000003, 0.14999999999999999, 1.75, 0.050000000000000003, 0.10000000000000001, 0.033333333333333333, 0.18333333333333332, 0.23333333333333334, 0.10000000000000001, 0.066666666666666666, 0.066666666666666666, 0.066666666666666666, 0.14999999999999999, 0.10000000000000001, 0.083333333333333329, 0.066666666666666666, 0.066666666666666666, 0.066666666666666666, 0.050000000000000003, 0.41666666666666669, 0.050000000000000003, 0.066666666666666666, 0.066666666666666666, 0.033333333333333333, 0.050000000000000003, 0.033333333333333333, 0.066666666666666666, 0.066666666666666666, 0.083333333333333329, 0.13333333333333333, 0.066666666666666666, 0.050000000000000003, 0.14999999999999999, 0.083333333333333329, 0.066666666666666666, 0.050000000000000003, 0.050000000000000003, 0.033333333333333333, 0.033333333333333333, 0.050000000000000003, 0.033333333333333333, 0.033333333333333333, 0.066666666666666666, 0.050000000000000003, 0.050000000000000003, 0.10000000000000001, 0.10000000000000001, 0.083333333333333329, 0.050000000000000003, 0.066666666666666666, 0.050000000000000003, 29.0]


plt.plot(bad_final_dates,bad_scaled_final_durations,'o-',picker=contains_points)
#plt.plot(good_final_dates,good_scaled_final_durations,'o-',picker=contains_points)

plt.ylabel('some numbers')
plt.show()

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to