Hi,

On Fri, 17 Feb 2006, Markus Meyer wrote:

> Hi everyone,
>
> I'm trying to draw graphs with discontinuities in it, like this:
>
> from pyx import *
> from math import cos, pi
>
> def f(x):
>    return cos(x % (pi/2))
>
> g = graph.graphxy(width=8, height=3.25, xpos=0, ypos=8, x2=None, y2=None,
>                   x=graph.axis.lin(min=0, max=5, title="$t [s]$"),
>                   y=graph.axis.lin(min=-0.3, max=1.3, title="$U(t) [V]$"))
> g.plot(graph.data.function("y(x)=f(x)", context=locals()),
> [graph.style.line()])
> g.writePDFfile("discont")
>
> However, there are two problems with this:
>
> 1. The vertical slopes between the single instances of the sawtooths are
> not perfectly vertical. In cases, where I want to explicitely visualize
> that a function has discontinuities, this is something that will
> probably make the reader stumble.
>
> 2. In most books, the vertical slopes are not displayed at all. I cannot
> currently do this with graph.data.function.
>
> When using a graph.data.paramfunction, it looks a bit better, but when
> zooming in, one can still see, that the slopes are not perfectly
> vertical. I know that I can use graph.data.list to exactly control the
> points that are output, but I guess there should be a better way?

I think you will have to split the plotting into parts, e.g.,
if you have Numeric or numpy or numarray installed, you could do

#################################################
from pyx import *
from math import pi
from Numeric import arange, cos

npts = 100
x = pi/2.0*arange(npts)/(npts-1)
y = cos(x)

g = graph.graphxy(width=8, height=3.25, xpos=0, ypos=8, x2=None, y2=None,
                  x=graph.axis.lin(min=0, max=5, title="$t [s]$"),
                  y=graph.axis.lin(min=-0.3, max=1.3, title="$U(t) [V]$"))
for i in xrange(4):
    g.plot(graph.data.list(zip(x+i*pi/2.0, y), x=1, y=2),
[graph.style.line()])

g.writePDFfile("discont")
##################################################

Of course you can construct x and y as lists, but then
adding i*pi/2.0 won't work.

Best, Arnd



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to