From: Rob Newman on 10 Mar 2010 13:54 Hi there, I have a series of graphs that are created in batches (up to 400) by a Matlab .m script. The y-axis values can range from less than +/- 2000 to over +/- 5000000. The Matlab auto labeling works well for small numbers (> +/-10,000) but any higher and it starts to plot the y-axis labels as (for example) -2.5, -1.25, 0, 1.25, 2.5 with a x10^4 label at the top of the plot. I need to avoid this labeling, and need real integers plotted along the y-axis. Is there any way I can over-ride the auto labeling that Matlab puts out? I also want the top-most YLabel and bottom-most YLabel to have the string "nm/sec" append to the label. Here is an example of what I currently get (A), and what I want (B): A. What I get from Matlab auto labeling. x 10^5 5.0 -| | | 2.5 -| | | 0 -| | | 2.5 -| | | 5.0 -| B. This is what I want: 500000 nm/sec -| | | 250000 -| | | 0 -| | | 250000 -| | | 500000 nm/sec -| I have tried to do this by creating a loop that assigns values to two cells - one for the values and one for the tick labels. I then determine the max range from all the values, and choose a number of ticks (5 in this case), and assign values to the cells within the for loop. I then use these cells to manually force the Y-axis values: my_y_range = my_y_max - my_y_min; my_y_ticks = 5; my_y_tickinterval = my_y_range / my_y_ticks; value_cell = cell(1,my_y_ticks); label_cell = cell(1,my_y_ticks); for i=1:my_y_ticks, value = my_y_min + (my_y_tickinterval * i); value_cell{i} = value; % If we are on the first and last tick value if i == 0 || i == my_y_ticks label_cell{i} = [ value ' nm/sec' ]; else label_cell{i} = value; end end % Later in script, get the current axes and set the Y ticks set( gca, 'YTick', cell2mat(value_cell), 'YTickLabel', label_cell ) ; However, this does not replicate the nice Matlab auto-scaling. So I guess I want to be able to pass the YTickLabel plot property some sort of function that will get the output I want. Does anyone have any suggestions? Thanks in advance. - Rob
From: Walter Roberson on 10 Mar 2010 14:16 Rob Newman wrote: > I have a series of graphs that are created in batches (up to 400) by a > Matlab .m script. The y-axis values can range from less than +/- 2000 to > over +/- 5000000. The Matlab auto labeling works well for small numbers > (> +/-10,000) but any higher and it starts to plot the y-axis labels as > (for example) -2.5, -1.25, 0, 1.25, 2.5 with a x10^4 label at the top of > the plot. I need to avoid this labeling, and need real integers plotted > along the y-axis. Is there any way I can over-ride the auto labeling > that Matlab puts out? plot normally, then get() the YTick property of the axis: the returned values will be the exact numeric positions of the ticks. Use sprintf() or num2str() to format the values however you like, and set() the YTickLabel property to the result. For example, set(gca, 'YTickLabel', num2str(get(gca, 'YTick'))); The numeric exponent like x 10^4 that you see only appears when the yticklabelmode is automatic, so it when you set the yticklabel, that numeric exponent will be removed.
From: Rob Newman on 10 Mar 2010 17:37 Walter Roberson <roberson(a)hushmail.com> wrote in message <hn8rnf$bsi$1(a)canopus.cc.umanitoba.ca>... > > plot normally, then get() the YTick property of the axis: the returned values > will be the exact numeric positions of the ticks. Use sprintf() or num2str() > to format the values however you like, and set() the YTickLabel property to > the result. > > For example, > > set(gca, 'YTickLabel', num2str(get(gca, 'YTick'))); > > The numeric exponent like x 10^4 that you see only appears when the > yticklabelmode is automatic, so it when you set the yticklabel, that numeric > exponent will be removed. Hi Walter, Thanks for the response. That makes sense. However, the code you list above appears to add all the tick mark values at every mark on the y-axis. So, instead of: x 10^5 5.0 -| | | 2.5 -| | | 0 -| | | - 2.5 -| | | - 5.0 -| I now get: -500000 -250000 0 250000 500000 -| | | -500000 -250000 0 250000 500000 -| | | -500000 -250000 0 250000 500000 -| | | -500000 -250000 0 250000 500000 -| | | -500000 -250000 0 250000 500000 -| Any ideas what could be causing that? Regards.
From: Rob Newman on 10 Mar 2010 17:45 "Rob Newman" <rlnewman(a)ucsd.edu> wrote in message > So, instead of: > > x 10^5 > 5.0 -| > | > | > 2.5 -| > | > | > 0 -| > | > | > - 2.5 -| > | > | > - 5.0 -| > > I now get: > > -500000 -250000 0 250000 500000 -| > | > | > -500000 -250000 0 250000 500000 -| > | > | > -500000 -250000 0 250000 500000 -| > | > | > -500000 -250000 0 250000 500000 -| > | > | > -500000 -250000 0 250000 500000 -| If I print out the values of: num2str(get(gca,'YTick')) I get the following output from Matlab: ans = -500000 -250000 0 250000 500000 ans = -500000 -250000 0 250000 500000 ans = -500000 -250000 0 250000 500000 ans = -500000 -250000 0 250000 500000 ans = -500000 -250000 0 250000 500000 So it looks like it gets the complete YTick matrix for each label value. Does that seem like correct behavior? FWIW, I am running Matlab Version 7.3.0.298 (R2006b) Thanks.
From: Walter Roberson on 10 Mar 2010 17:37 Rob Newman wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message >> set(gca, 'YTickLabel', num2str(get(gca, 'YTick'))); > Thanks for the response. That makes sense. However, the code you list > above appears to add all the tick mark values at every mark on the y-axis. Sorry, minor correction: set(gca, 'YTickLabel', num2str(get(gca, 'YTick').')); Notice the addition of the .' after the get() call; it transforms the row vector into a column vector so that num2str() will produce a column of individual labels instead of a combined single row of labels.
|
Next
|
Last
Pages: 1 2 Prev: how to set current zoom setting for next execution? Next: Resample Data to Match X-values |