boyfarrell.com

14 January 2008

ChocPlot: First Results

Cocoa Plot View

It has been quite slow going with the plotting framework as of late; the trouble with being in the fourth year of a three year PhD! I have decided to rely on Cocoa for as much as possible for the plot above (under the advice of Wil Shipley). I am using NSBezierPath to draw the red dashed line and the filled the circles. NSAffineTransform is used to convert data points from data to screen/view coordinates.

A lot for free

Using NSAffineTransform makes it very easy to position and also alter the points (which themselves are drawn with NSBezierPath) in the view, e.g. rotation of the data points by 23 degrees in the example below. One just needs to specify a ‘data’ coordinate rectangle which is made from the min, max and range of the experimental data set in x and y. A NSAffineTransform is made such that the ‘data’ rectangle is first translated and then scaled to fit into the view bounds. Hmmm I lke ‘tiny code’ …

Cocoa Plot View with crosses

Drawing lines is made very easy, using NSBezierPath’s setLineDash:count:phase: method. Also, drawing oval/circles comes for free with bezierPathWithOvalInRect: method. So the only really work I have actually done is added bezierPathWithCrossInRect: extension to aid drawing of crosses (shown above)!

Next step…

Next I will add a points-lines plotting style. This will be similar to drawing a dashed lines but will have ovals or crosses, and regular points along it’s length. A nice touch would be to have the rotation of the points follow the gradient of the line; think of the way loops in chain would rotate as of a chain changes direction.

Also, we will implement the code from the first few chocplot plots and have nicley spaced axis labels on the plot.

No Comments currently posted.

Post a comment on this entry: