plotting different sized circles [message #86110] |
Mon, 07 October 2013 08:12  |
Krishnakumar M.A
Messages: 19 Registered: March 2013
|
Junior Member |
|
|
Hi all,
I'm having a bit trouble here while using usersym. What I want to make is circles with the third column of the file (which means that the circles will have different radii). But, I have no idea if one can use the usersym like the way in which I have used. the code and the error message is given below. Please let me know the problem with the script.
Thanks.
data=fltarr(3,100)
readf,1,data
l=data(0,*)
b=data(1,*)
r=data(2,*)
for i=0,99 do begin
n=17.0
theta=findgen(n)/(n-1.0)*360.0
x(i)=l(i)+r(i)*sin(theta)/1.0
y(i)=b(i)+r(i)*cos(theta)/1.0
usersym,x(i),y(i)
plot,l(i),b(i),psym=8
endfor
The returned error was
% Compiled module: $MAIN$.
% USERSYM: Expression must be an array in this context: <FLOAT (
-1.99965)>.
% Execution halted at: $MAIN$ 16
|
|
|
Re: plotting different sized circles [message #86111 is a reply to message #86110] |
Mon, 07 October 2013 08:28   |
suicidaleggroll
Messages: 14 Registered: September 2013
|
Junior Member |
|
|
On Monday, October 7, 2013 9:12:13 AM UTC-6, Krishnakumar M.A wrote:
> Hi all,
>
>
>
> I'm having a bit trouble here while using usersym. What I want to make is circles with the third column of the file (which means that the circles will have different radii). But, I have no idea if one can use the usersym like the way in which I have used. the code and the error message is given below. Please let me know the problem with the script.
>
>
>
> Thanks.
>
>
>
> data=fltarr(3,100)
>
> readf,1,data
>
> l=data(0,*)
>
> b=data(1,*)
>
> r=data(2,*)
>
>
>
> for i=0,99 do begin
>
> n=17.0
>
> theta=findgen(n)/(n-1.0)*360.0
>
> x(i)=l(i)+r(i)*sin(theta)/1.0
>
> y(i)=b(i)+r(i)*cos(theta)/1.0
>
> usersym,x(i),y(i)
>
>
>
> plot,l(i),b(i),psym=8
>
> endfor
>
>
>
> The returned error was
>
>
>
> % Compiled module: $MAIN$.
>
> % USERSYM: Expression must be an array in this context: <FLOAT (
>
> -1.99965)>.
>
> % Execution halted at: $MAIN$ 16
I'm not sure why you want/need to use usersym in the first place. You've already calculated the x and y locations, so just plot them directly.
Also - sin/cos work on radians, not degrees, and you have your sin and cos backwards in regards to x and y, and I'm not sure why you're dividing them by 1. Also, x and y are not preallocated, so you can't start subscripting them as if they're existing arrays, and even if they were preallocated, it would break because you're trying to store an entire 17 element array into a single element.
You'll also want to reform your l, b, and r arrays so they're N elements rather than 1xN elements. The latter can cause some funky issues later on.
Keep in mind that by using plot inside the for loop, you're going to end up with 100 separate plots, one point on each. I doubt this is what you truly want, so you probably want to make the plot outside of the loop, and then oplot inside.
data=fltarr(3,100)
readf,1,data
l=reform(data[0,*])
b=reform(data[1,*])
r=reform(data[2,*])
plot, [0,1], [0,1], /nodata, xrange=?, yrange=?
for i=0,99 do begin
n=17.0
theta=findgen(n)/(n-1.0)*2*!pi
x=l(i)+r(i)*cos(theta)
y=b(i)+r(i)*sin(theta)
oplot,x,y
endfor
|
|
|
Re: plotting different sized circles [message #86112 is a reply to message #86110] |
Mon, 07 October 2013 08:58   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Krishnakumar M.A writes:
> I'm having a bit trouble here while using usersym. What I want to make is circles with the third column of the file (which means that the circles will have different radii). But, I have no idea if one can use the usersym like the way in which I have used. the code and the error message is given below. Please let me know the problem with the script.
Draw your circle on a unit square, then use SYMSIZE to size it.
Plot, x, y, PSYM=cgSymCat(16), SymSize=radiusIwant
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: plotting different sized circles [message #86113 is a reply to message #86111] |
Mon, 07 October 2013 09:00  |
Krishnakumar M.A
Messages: 19 Registered: March 2013
|
Junior Member |
|
|
On Monday, October 7, 2013 8:58:18 PM UTC+5:30, suicida...@gmail.com wrote:
> On Monday, October 7, 2013 9:12:13 AM UTC-6, Krishnakumar M.A wrote:
>
>> Hi all,
>
>>
>
>>
>
>>
>
>> I'm having a bit trouble here while using usersym. What I want to make is circles with the third column of the file (which means that the circles will have different radii). But, I have no idea if one can use the usersym like the way in which I have used. the code and the error message is given below. Please let me know the problem with the script.
>
>>
>
>>
>
>>
>
>> Thanks.
>
>>
>
>>
>
>>
>
>> data=fltarr(3,100)
>
>>
>
>> readf,1,data
>
>>
>
>> l=data(0,*)
>
>>
>
>> b=data(1,*)
>
>>
>
>> r=data(2,*)
>
>>
>
>>
>
>>
>
>> for i=0,99 do begin
>
>>
>
>> n=17.0
>
>>
>
>> theta=findgen(n)/(n-1.0)*360.0
>
>>
>
>> x(i)=l(i)+r(i)*sin(theta)/1.0
>
>>
>
>> y(i)=b(i)+r(i)*cos(theta)/1.0
>
>>
>
>> usersym,x(i),y(i)
>
>>
>
>>
>
>>
>
>> plot,l(i),b(i),psym=8
>
>>
>
>> endfor
>
>>
>
>>
>
>>
>
>> The returned error was
>
>>
>
>>
>
>>
>
>> % Compiled module: $MAIN$.
>
>>
>
>> % USERSYM: Expression must be an array in this context: <FLOAT (
>
>>
>
>> -1.99965)>.
>
>>
>
>> % Execution halted at: $MAIN$ 16
>
>
>
> I'm not sure why you want/need to use usersym in the first place. You've already calculated the x and y locations, so just plot them directly.
>
>
>
> Also - sin/cos work on radians, not degrees, and you have your sin and cos backwards in regards to x and y, and I'm not sure why you're dividing them by 1. Also, x and y are not preallocated, so you can't start subscripting them as if they're existing arrays, and even if they were preallocated, it would break because you're trying to store an entire 17 element array into a single element.
>
>
>
> You'll also want to reform your l, b, and r arrays so they're N elements rather than 1xN elements. The latter can cause some funky issues later on.
>
>
>
> Keep in mind that by using plot inside the for loop, you're going to end up with 100 separate plots, one point on each. I doubt this is what you truly want, so you probably want to make the plot outside of the loop, and then oplot inside.
>
>
>
> data=fltarr(3,100)
>
> readf,1,data
>
> l=reform(data[0,*])
>
> b=reform(data[1,*])
>
> r=reform(data[2,*])
>
>
>
> plot, [0,1], [0,1], /nodata, xrange=?, yrange=?
>
> for i=0,99 do begin
>
> n=17.0
>
> theta=findgen(n)/(n-1.0)*2*!pi
>
> x=l(i)+r(i)*cos(theta)
>
> y=b(i)+r(i)*sin(theta)
>
>
>
> oplot,x,y
>
> endfor
Thanks a lot. That was a great help for me.
As I said, I never used usersym in IDL, since I always use some other language to do plotting. But as I came to know that it will be easier in IDL, I tried my hand.
Thanks for the help.
|
|
|