## [PyX-user] Smoother function plots by adaptive sampling (with code)

 [PyX-user] Smoother function plots by adaptive sampling (with code) From: Brendon Higgins - 2010-08-25 10:21:54 Attachments: adaptivefunction.py ```Hi list, I grew frustrated with the coarseness of control of graph.data.function. You can specify the number of points, but it's quite suboptimal if the gradient of your function varies significantly, especially if that variation in gradient is only confined to a small region. So, instead of finishing my thesis like I *really* ought to be doing, I wrote the attached extension, the adaptivefunction class. This works just like graph.data.function, except that after generating all the linearly separated points, it will do a second pass and adaptively add in-between points. It chooses to do this based on how much the angle differs between two adjacent lines (three adjacent points). If the angle differs by more than the angle epsilon (a new constructor parameter) then it will split the two lines into four lines by adding two new points. What this means is that adaptivefunction uses points more efficiently than function does for the same number of points, and it should result in better looking function plots with smaller file sizes. adaptivefunction tries to take into account the scale and shape of the rendered plot when determining the angles; it adapts to optimise the visual result. One caveat with this is that I'm not sure how to handle the case when the y axis range is not specified or cannot be inferred from other data. (Are the min and max values of the axis class None in that case? That seems to be the case.) I've played around with it a bit. It works fine on both linear and log plots (I should know, as it took me several hours to figure out how to work around precision issues with the log plots). It's fun giving it 3 starting points and a small epsilon, and seeing it produce a lovely smoothed plot. Thought I'd share. Enjoy. :-) Peace, Brendon ```

 [PyX-user] Smoother function plots by adaptive sampling (with code) From: Brendon Higgins - 2010-08-25 10:21:54 Attachments: adaptivefunction.py ```Hi list, I grew frustrated with the coarseness of control of graph.data.function. You can specify the number of points, but it's quite suboptimal if the gradient of your function varies significantly, especially if that variation in gradient is only confined to a small region. So, instead of finishing my thesis like I *really* ought to be doing, I wrote the attached extension, the adaptivefunction class. This works just like graph.data.function, except that after generating all the linearly separated points, it will do a second pass and adaptively add in-between points. It chooses to do this based on how much the angle differs between two adjacent lines (three adjacent points). If the angle differs by more than the angle epsilon (a new constructor parameter) then it will split the two lines into four lines by adding two new points. What this means is that adaptivefunction uses points more efficiently than function does for the same number of points, and it should result in better looking function plots with smaller file sizes. adaptivefunction tries to take into account the scale and shape of the rendered plot when determining the angles; it adapts to optimise the visual result. One caveat with this is that I'm not sure how to handle the case when the y axis range is not specified or cannot be inferred from other data. (Are the min and max values of the axis class None in that case? That seems to be the case.) I've played around with it a bit. It works fine on both linear and log plots (I should know, as it took me several hours to figure out how to work around precision issues with the log plots). It's fun giving it 3 starting points and a small epsilon, and seeing it produce a lovely smoothed plot. Thought I'd share. Enjoy. :-) Peace, Brendon ```