Here's a simple example of what I mean:

Depending on whether you use 100 or 101 points, "y(x)=1/x" is plotted
with or without a spurious almost vertical line at 0.

The reason is that with 101 points, one evaluation throws a ZeroDivision
exception which graph.data.function catches and turns into "y=None",
which tells graph.style.line to cut the line.

With 100 points, "singular" values" merely reach 50, which is way beyond
my clipping range but not that far on the way to infinity, of course.

In my third example, I demonstrate what I mean by range cutting using a
wrapper. This again avoids the extra vertical line.

I think the graph.data.function() family (or the line style?) could
really use an absmax argument, or ymin and ymax, which would turn on a
rangecutter.

Having this on by default would be useful, but the example also shows
that a good default value would be difficult to choose - it could be
based on the min and max for the yaxis (times 10 or so), although that
could cause other problems.

Michael

P.S.: I'm not sure about this list's policy reagrding attachments. Sorry
if the pdf should be out of place.
#!/usr/bin/python3

from pyx import *

def rangecutter(x, bound=20):
	if (abs(x) < bound):
		return x
	return None

unit.set(wscale=10)

g = graph.graphxy(width=10, ratio=1,
	x=graph.axis.linear(min=-2, max=2),
	y=graph.axis.linear(min=-2, max=2))

g.plot(graph.data.function("y(x)=1/x", points=100), [graph.style.line([color.rgb.red, style.linewidth.THick])])
g.plot(graph.data.function("y(x)=1/x", points=101), [graph.style.line([color.rgb.green, style.linewidth.Thick])])
g.plot(graph.data.functionxy(lambda x: rangecutter(1/x), points=100), [graph.style.line([color.rgb.blue])])
g.writePDFfile()

Attachment: singular.pdf
Description: video/flv

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to