Polor Plot
Posted: Thu Sep 01, 2005 6:04 am
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!
Thanks!
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
Code: Select all
d.ScaleCode = SCALE_POLAR + UNITS_POLAR_DEGREES
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 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
[PolarPlotStyle(7)]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?