Left and right axis with common zero

Hi,

I want to modify a graph with a left and a right y axis in a way that the zero points of both are in the same height, but the axes should still have different scales and not necessarily be Symmatric around zero.

The Data I'm using can look something like this:

•Make/N=100 DataL=gnoise(5)
•Make/N=100 DataR=gnoise(0.2)-0.2
•Display/L DataL
•AppendToGraph/R DataR

Does Somebody know how to do this?

Thank you for your time,

sincerely,

Sven

This is close, I think:

Function DoStuff()
	Make/O/N=100 DataL=gnoise(5)
	Make/O/N=100 DataR=gnoise(0.2)-0.2
	Display/L /N=myGraph DataL
	AppendToGraph/R DataR
	SetWindow myGraph, hook(alignZero)=AlignZeroHook
End

Function AlignZeroHook(s)
	STRUCT WMWinHookStruct &s

	Variable hookResult = 0

	switch(s.eventCode)
		case 8:				// Modified
			
			GetAxis/W=myGraph left
			variable vLeftRange = V_max - V_min
			Variable vLeftMin = V_min
			GetAxis/W=myGraph right
			variable vRightRange = V_max - V_min
			Variable vRightMin = V_min
			
			Variable vNewRightMin = vLeftMin * vRightRange / vLeftRange
			
			SetAxis/W=myGraph right vNewRightMin, (vNewRightMin + vRightRange)
			hookResult = 1
			
			break
	endswitch

	return hookResult		// 0 if nothing done, else 1
End

Hope this gives some ideas,

Kurt

 

Hello Kurt,

I like the idea. The Problem here is that in your code the range is kept constant, thus a part of the Data is not visible anymore. So I Changed it a little bit:

Function AlignZeroHook(s)
	STRUCT WMWinHookStruct &s

	Variable hookResult = 0
	
		switch(s.eventCode)
			case 8:             // Modified
				
				//Go to automatic Scaling of right axis to get hole DataRange
				SetAxis/W=$(s.WinName)/A right
				DoUpdate;

				GetAxis/Q /W=$(s.WinName) left
				Variable LMax = V_max
				Variable LMin = V_min
				variable LRng = V_max - V_min
				GetAxis/Q /W=$(s.WinName) right
				variable RMax = V_max
				Variable RMin = V_min
				Variable RRng = V_max - V_min
				
				//look whether the top or the lower range have to be extended
				If(RMax/RRng>LMax/LRng)
					Variable NewRMin=RMax-(RMax/LMax*LRng)
					SetAxis/W=$(s.WinName) right NewRMin, *
				else
					Variable NewRMax=(RMin/LMin*LRng)+RMin
					SetAxis/W=$(s.WinName) right *, NewRMax
				endif
				hookResult = 1
           
				break
		endswitch

	return hookResult       // 0 if nothing done, else 1
End

It now just get stuck if the left axis has no zero at all.

Thank you very much.

Sincerly,

Sven