Category Plot starting not from zero
ChrisZ
Is there any option to make a category/bar plot, where the bars do not start from zero? In my case I need them to start from 1 and extending in both directions to values ranging from 0.1 to 10.
Additionally I want to have it with a logarithmic scale, which I suppose wouldn't cause any further problems as soon as the first problem is solved.
Attached you see an example done with Excel (which is why I think there is no possibilty Igor can handle this, but I just couldn't find a possibilty)
Thank you for your help and best regards,
Chris
Reproducing the axis crossing at 1 instead of being at the edge, and having the bars stick out from the axis in both directions, requires some trickery. Let me know if you're interested in my trickery.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 3, 2015 at 10:13 am - Permalink
Thanks for your reply. I had already managed to swap the axes, but then failed in shifting the axis and changing the origin of the bars.
So, yes, I'm very interested in your trickery ;-)
What you suggested so far gives the plot attached. Looks good, but i really need the origin at 1.
What will be plotted is a ratio of two values, which results in two groups, i.e. >1 and <1. These groups can be identified on first glance, if the bars have their origin at 1.
Thanks again and best wishes,
Chris
June 4, 2015 at 12:42 am - Permalink
The trick is to make a dummy wave with the same number of points as your data waves. Fill it with the number you want to be at the center of the graph. Now make your category plot and after each data wave, append a new trace made with the dummy wave. Then set the Grouping mode of the real data trace to "Draw To Next". That will cause the bars to draw to the position of the dummy trace instead of to the edge of the plot.
In order to not see the dummy traces, hide the dummy traces
In order to get the axis along the center line instead of at the edge of the plot, use a free axis and set its positioning mode to "Crossing at".
In order to see the axis even though some of the bars will cross over it, turn on the "On top of traces" mode.
I could spend a lot of time explaining, and giving links to the help... Here is a function that encapsulates all of this, making the basic graph for you:
Wave/T textwave
String yWaveLIst
Variable centerNumber
Variable nYWaves = ItemsInList(yWaveList)
Variable nCategories = NumPnts(textwave)
Variable i
// Sanity checks
for (i = 0; i < nYWaves; i += 1)
String ywname = StringFromList(i, yWaveList)
Wave/Z yw = $ywname
if (!WaveExists(yw))
DoAlert 0, "The wave \""+ywname+"\" does not exist"
return -1
endif
if (numpnts(yw) != nCategories)
DoAlert 0, "The number of points in the wave \""+ywname+"\" does not match the category wave"
return -1
endif
endfor
Display
String gname = S_name
// Make a dummy wave to fill with the center number for Draw to Next grouping mode
Make/O/N=(nCategories) $(gname+"dummy"+num2str(i))/WAVE=dummyw
dummyw = centerNumber
// Append each data wave to the graph, followed by a dummy trace. Set the styles on the two traces
// to set the Draw to Next mode on the data trace, set lines mode for the dummy trace, and hide the dummy trace.
for (i = 0; i < nYWaves; i += 1)
ywname = StringFromList(i, yWaveList)
Wave yw = $ywname
AppendToGraph/W=$gname/B=CategoryAxis yw vs textwave
String dummyTraceName = "DummyTrace"+num2str(i)
AppendToGraph/W=$gname/B=CategoryAxis dummyw/TN=$(dummyTraceName) vs textwave
ModifyGraph mode($dummyTraceName)=0
ModifyGraph hideTrace($dummyTraceName)=1
ModifyGraph toMode($ywname)=1
endfor
// Put the category axis above the traces so you can see the tick labels on top of the bars
ModifyGraph axisOnTop(CategoryAxis)=1
// Set the category axis to cross the left axis at the center value
ModifyGraph freePos(CategoryAxis)={centerNumber,left}
end
You feed it the name of your text wave containing the category text, then a list of the Y waves, then the number you want at the center of the plot (1 in your case). Here is an example with made-up data waves:
make/n=10 yw2=enoise(2)+1 // another fake data wave centered about 1
make/n=10/T twave="row "+num2str(p+1) // a text wave with fake categories
CategoryPlotAroundNumber(twave, WaveList("yw*", ";", ""), 1) // Make the graph using the function above
This function does not try to color the bars, it does not set log mode, and it does not apply the SwapXY mode to the graph. But it will make the basic graph that you can enhance in any way you wish.
I have attached a picture of a graph that I made using the function. I gave the bars some nice coloring after I made it.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Edited to add a couple comments, and to correct a mistake: the axis position is now correctly set.
June 4, 2015 at 10:07 am - Permalink
And it also seems that I almost had it before. I had created the dumy waves and tried around with grouping (I think "stack to next"). I got al the bars <1 correct but for the ones >1 I got no bars, but only vertical lines, where the bars should end.
Well, thanks again and have I nice weekend!
Chris
June 4, 2015 at 11:03 pm - Permalink
You're welcome. This should be easier!
Gosh. I'm not sure I would know how to do that if you actually wanted it :)
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 5, 2015 at 09:32 am - Permalink