Page 1 of 1

Polor Plot

Posted: Thu Sep 01, 2005 6:04 am
by bartj
Can anyone provide some vb(not .net) code for generating a polor plot? The dplot example file: ex03.grf represents what I would like to "see".
Thanks!

Posted: Thu Sep 01, 2005 9:18 am
by DPlotAdmin
This will reproduce ex03.grf:

Code: Select all

Option Explicit
Option Base 0
Dim d As DPLOT

Private Sub Command6_Click()

    Dim i As Long
    Dim NP As Long
    Dim X() As Single
    Dim Y() As Single
    Dim PI As Single
    Dim cmds As String
    Dim ret As Long
    Dim DocNum As Long
    
' Plot sin(3*x) from x = 0 to 2PI

    PI = 4# * Atn(1#)
    NP = 1001
    ReDim X(0 To NP - 1) As Single
    ReDim Y(0 To NP - 1) As Single
    
    For i = 0 To NP - 1
        X(i) = (2# * PI * i) / (NP - 1)
        Y(i) = Abs(Sin(3 * X(i)))
    Next i
        
    d.version = DPLOT_DDE_VERSION
    d.DataFormat = DATA_XYYY
    d.MaxCurves = 1
    d.MaxPoints = NP
    d.NumCurves = 1
    d.ScaleCode = SCALE_POLAR
    d.NP(0) = NP
    d.LineType(0) = LINESTYLE_SOLID
    d.Title1 = "abs(sin(3{\sf}))"
    d.Title2 = ""
    d.Title3 = ""
        
    cmds = "[ManualScale(0,0,0,1.2)]"                   ' X limits are ignored
    cmds = cmds & "[TickInterval(2,30,0.2)]"            ' 1st "2" says X interval is in degrees
    cmds = cmds & "[Caption(""DPLOTLIB XY Test"")]"
    cmds = cmds & "[NumberFormat(0,8)]"                 ' PI Fractions
    cmds = cmds & "[ClearEditFlag()][DocMaximize()]"
    DocNum = DPlot_Plot(d, X(0), Y(0), cmds)
 
End Sub
If you want X in degrees rather than the default radians, use

Code: Select all

    d.ScaleCode = SCALE_POLAR + UNITS_POLAR_DEGREES

Thanks

Posted: Thu Sep 01, 2005 3:11 pm
by bartj
David,

Thanks for the quick reply.

Will look it over.

Another request

Posted: Fri Sep 02, 2005 3:45 am
by bartj
Hello,

Am looking at using dplot in an antenna measurement system where I will plot the signal strength on a polor plot. I setup the plot to use degrees instead of radians and then used the folloing to generate some dummy points:

For i = 1 To 360
X(i) = i ' this generates the angular steps
Y(i) = 0.75 ‘ this is my dummy data – will just represent a circle
Next i

Note that I set NP to 361

I note however that there is a line from the origin at zero degrees to the dummy circle. Is there any way to inhibit this line?

Would also like to set the top to be zero degrees and have the angles change in the clockwise direction. Is there an easy way to accomplish this?

Thanks!

1 question answered

Posted: Fri Sep 02, 2005 4:46 am
by bartj
Hello,

I find that I can eliminate the line from the origin(of a polar plot) to the "circle" by changing my starting index from 1 to 0.

For i = 0 To 360
X(i) = i ' this generates the angular steps
Y(i) = 0.75 ' dummy data
Next i

However I would still like to know how to place zero degrees at the top of a polar plot and have the angles step CW and be labeled in degrees.

Thanks again...

1 step forward, one step back

Posted: Fri Sep 02, 2005 5:28 am
by bartj
OK,

I find that I can set the ploar plot rotation axis to be labeled in degrees.

However when I use the following to set zero degrees to the top and to set a CW direction, it "works", but the grid becomes an elipse instead of a circle:

cmds = cmds & "[PolarPlotStyle(3)]"

Is there another approach that will NOT cause the plot to appear as an elipse?

Thanks!

Posted: Fri Sep 02, 2005 9:36 am
by DPlotAdmin
I find that I can eliminate the line from the origin(of a polar plot) to the "circle" by changing my starting index from 1 to 0.

For i = 0 To 360
X(i) = i ' this generates the angular steps
Y(i) = 0.75 ' dummy data
Next i
Just so we're clear, this is because the examples use Option Base 0. So in your previous example the first X,Y pair was an uninitialized 0,0.
I find that I can set the ploar plot rotation axis to be labeled in degrees.

However when I use the following to set zero degrees to the top and to set a CW direction, it "works", but the grid becomes an elipse instead of a circle:

cmds = cmds & "[PolarPlotStyle(3)]"

Is there another approach that will NOT cause the plot to appear as an elipse?
[PolarPlotStyle(7)]

The 4 (3+4=7) is "Forces a circular plot". This is actually a bit of a hack; all it does is set the plot width and height to 5" (or smaller, depending on what will fit). If you want a bigger plot then also use

[Size(1,w,h,1)]

where w=h=size of plot in inches.