Andrea Gavana continues to struggle with his parallel lines:
> I managed to get *almost* there, but there still is a small glitch. I
> attach a self-evident sample, which generates data very similar to the
> real ones I have and shows the two "parallel" curves to the main one.
>
> You will notice that the "parallel" curves look parallel almost all
> the time, except in a few areas (I have annotated the plot for
> reference). I can't see the reason for this difference, but it is
> obvious I am missing something.
Yes. I am afraid it it not a small glitch, but a serious bug.
Actually, there are still two things. The second one is the purely 
visual scaling based on the aspect of your figure on the screen, and I 
will not discuss it now, you can get into your axes, pick the frame, dig 
out the extent, extract the "points" of the rectangle, and do some other 
dirty stuff, which will get wrong when you touch your figure... So, here 
- I believe - is better to adjust things by hand.

But the REAL STUFF is elsewhere. You added a vertical scaling, as I 
suggested, based on the aspect ratio of your data. You rescaled the 
offsets. I believe that I might have suggested that, if this is the 
case, I am sorry, it was a mental abbreviation...

Rescaling JUST the offsets, and keeping the function itself in a 
"distorted frame" is sinful. Here you are another attempt. With (or 
without) your permission, I reconstruct the offset without your 
!*##$%*!! arctan... This is my equivalent of your "get-normal points" :

def adp(x):  # This computes the derivative without splines or other 
heavy artillery.
     xa=numpy.concatenate(([2*x[0]-x[1]],x,[2*x[-1]-x[-2]]))
     return xa[2:]-xa[:-2]
def para(x,y,dst,ax):  # ax is the current axes set, dst is the offset.
     scal=ax.get_data_ratio() # Don't send human make the work of a machine!
     y0=y/scal          # Warp the original
     dx=adp(x); dy=adp(y0)
     ds=dst/numpy.sqrt(dx*dx+dy*dy)
     x1=x-ds*dy; x2=x+ds*dy
     y1=y0+ds*dx; y2=y0-ds*dx
     return (x1,y1*scal,x2,y2*scal)

As you see, the function got "undistorted", the offsets calculated, and 
Mister Sulu, get us back into the real space !
Now, within your main() :

...
fig = plt.figure(figsize=(fw,fh))  # whatever...
ax = plt.subplot(111)
ax.plot(x, y, color='orange', ls='-', lw=3, label='data', zorder=30)  # 
It should be done first
...
ax.set_xlim(xlims)
ax.set_ylim(ylims)
ax.grid()
ax.invert_yaxis()
...
xh,yh,xl,yl = para(x,y,distance,ax)  # Here you are.
ax.plot(xl, yl, 'g-',zorder=30)
ax.plot(xh, yh, 'b-',zorder=30)

=================

OK, let's get back to the second problem. Here you have the additional 
scaling.

def vscal(ax):
     gf=ax.get_frame()
     ex=gf.get_extents()
     po=ex.get_points()   # What a lousy way ! Probably Ben R. knows 
some more direct access.
     w,h = po[1,0]-po[0,0], po[1,1]-po[0,1]
     return h/w

And within para(), the first line becomes:

scal=ax.get_data_ratio()/vscal(ax)

However, since my insomnia doesn't necessarily mean that I am fully 
conscious, check everything twice. Add your
fig.subplots_adjust, and recheck.

Good luck.

Jerzy K.


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to