possible?: changing tickValues in IDL - idl-programming-language

how can I change the tickvalues of 3D axes in IDL? I have a data array of 200 x 200, and the tick values range from 0 to 200. But I want to have tickvalues from 3417000 to 3419000 for x and from 5334000 to 5336000 for y.
Thanks a lot,
Harald

I just found the solution for my problem:
!X.TICKNAME = ['3417000', '3417500', '3418000', '3418500', $
'3419000']
!X.TICKS = 4
Thanks,
Harald

I would suggest using the keywords XTICKNAMES and XTICKS instead of the global system variables.

Related

how to set octave x-axis limitation and interval

I want to plot a graph in octave in which the x-axis maximum value is 2048, and the they start with 0 and increment by 100.
The y data is a vector of 2049 numbers.
here is my code :
ydata = load ("data.txt");
x = linspace(1,2048,2048);
plot(x,ydata(:,1));
this figures the x-axis with maximum value of 2500.
To add to Silver's answer, you might also want to set the XTick property of the axes:
ydata = rand(2048,1);
plot(ydata(:,1))
xlim([0 2048])
set(gca,'XTick',0:100:2048)
This produces the following, which I think is what you're after (note the axis labels are a bit on top of each other but that's because you wanted them every 100 - changing the aspect ratio of the figure will help):
I think what you are looking for is xlim
xlim([0 2048]);
That will limit the x-axes in the plot between 0 and 2048.
See the documentation here for more info.

how to change the color of a portion of QwtCurvePlot?

I'm using QwtCurvePlot to plot a 2d graph. the y axis range is 0 to 100 and x axis is 0 to 60. I use SetRawSamples to initialize my data. say I want to change the colors of portion of graph that y value is between 50 and 60. is there any one can help me please?
EDIT: I want something like
you should reimplement QwtPlotZoneItem draw function in horizontal orientation.If you think you need more in-depth answer comment me.

Re-classifying a random matrix

I am brand new to R and in some desperate need of help. I have created a random matrix and need to re-classify it. Each pixel is randomly generated from 0-255 and I need to able to classify the 0-255 digits into 8 classifications. How would I do this? Any help would be greatly appreciated and I have placed my code below. I know I could use a raster but I am unsure on how to use them.
Thanks
par(mar=rep(0,4))
m=matrix(runif(100),10,10)
image(m,axes=FALSE,col=grey(seq(0,1,length=255)))
I didn't think your example adequately fit your description of the problem (since runif only ranges from 0-1 if the limits are not specified) so I modified it to fit the natural language features:
m=matrix(runif(100, 0, 255),10,10)
m[] <- findInterval(m, seq(0, 256, length=8) )
image(m,axes=FALSE,col=grey(seq(0,1,length=255)))
The "[]" with no indices preserves the matrix structure of the m object. The findInterval function lets you do the same sort of binning as cut, but it returns a numeric vector rather than the factor that cut would give.

When plotting a curve in R, a piece of the curve gets cut off, not sure why

I am trying to plot this formula. As x approaches 0 from the right, y should be approaching infinity, and so my curve should be going upwards close to y-axis. Instead it gets cut off at y=23 or so.
my_formula = function(x){7.9*x^(-0.5)-1.3}
curve(my_formula,col="red",from=0 ,to=13, xlim=c(0,13),ylim=c(0,50),axes=T, xlab=NA, ylab=NA)
I tried to play with from= parameter, and actually got what I needed when I
put from=-4.8 but I have no idea why this works. in fact x doesn't get less than 0, and from/to should represent the range of x values, Do they? If someone could explain it to me, this would be amazing! Thank you!
By default, curve only chooses 101 x-values within the (from, to) range, set by the default value of the n argument. In your case this means there aren't many values that are close enough to 0 to show the full behaviour of the function. Increasing the number of values that are plotted with something like n=500 helps:
curve(my_formula,col="red",from=0 ,to=13,
xlim=c(0,13),ylim=c(0,50),axes=T, xlab=NA, ylab=NA,
n=500)
This is due mainly to the fact that my_formula(0) is Inf:
So plotting from=0, to=13 in curve means your first 2 values are by default (with 101 points as #Marius notes):
# x
seq(0, 13, length.out=101)[1:2]
#[1] 0.00 0.13
# y
my_formula(seq(0, 13, length.out=101)[1:2])
#[1] Inf 20.61066
And R will not plot infinite values to join the lines from the first point to the second one.
If you get as close to 0 on your x axis as is possible on your system, you can make this work a-okay. For instance:
curve(my_formula, col="red", xlim=c(0 + .Machine$double.eps, 13), ylim=c(0,50))

Change x axis to scale with pi and not numbers

I want to create the plot of cos(x) and sin(x) in Octave. I have learned how to change things such as xlabel and xlim, however I can’t find how to change from having numbers (e.g 1, 2, 3) to having pi terms (-pi,-pi/2 and such). I would also appreciate if you can explain me how to do that. Here is a picture of what I want to do in case my english confused you.
In Matlab you can do something like this:
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
As you can see here: http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html
This should work in Octave as well.
Also I haven't tested this but to get the actual Pi symbol you might try:
set(gca,'XTickLabel',{'-p','-p/2','0','p/2','p'}, 'fontname','symbol')
Otherwise you can try and see if this Matlab FEX submission will work for you: http://www.mathworks.com/matlabcentral/fileexchange/15986
For the π symbol you only have to write \pi.
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'})
This is an old topic, but here is an Octave solution with a bit of context.
Shadowing #Dan's input with #Chimalis's revision, the following script works in Octave 4.4.1 on Windows and 5.2.0 on Linux. Pay particular attention to the use of xtick, xticks, xticklabel, and xticklabels.
x = linspace(-3*pi,3*pi);
figure;
hold on;
subplot(2,1,1);
y = cos(x);
plot(x,y)
ylabel('cosine');
xticks([-3*pi -2*pi -pi 0 pi 2*pi 3*pi]);
xticklabels({'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'});
yticks([-1 -0.866 -0.707 -0.5 0 0.5 0.707 0.866 1]);
grid on;
sp_h2 = subplot(2,1,2);
z = sin(x);
plot(x,z)
sp_h2_pos = get(sp_h2, 'Position');
sp_h2_pos_new = sp_h2_pos - [0 0 sp_h2_pos(3)/2 0];
set(sp_h2, 'Position', sp_h2_pos_new);
ylabel('sine')
xlim([0 2*pi]);
h=get (gcf, "currentaxes");
set(h,"xtick",0:pi/2:2*pi);
set(h,"xticklabel",['0';'\pi/2';'\pi';'3\pi/2';'2\pi']);

Resources