Showing with 521 additions and 5 deletions.
  1. +12 −0 pyKst/demo/exportpng.py
  2. +27 −0 pyKst/demo/pykstplotdemo.py
  3. +44 −3 pyKst/html/index.rst
  4. +28 −0 pyKst/pykst.py
  5. +388 −0 pyKst/pykstplot.py
  6. +1 −1 pyKst/setup.py
  7. +4 −1 src/datasources/bis/bisdatasource.cpp
  8. +16 −0 src/libkstapp/scriptserver.cpp
  9. +1 −0 src/libkstapp/scriptserver.h
12 changes: 12 additions & 0 deletions pyKst/demo/exportpng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("TestX2")

v1 = client.new_generated_vector(-10, 10, 1000)
e1 = client.new_equation(v1, "sin(x)")
c1 = client.new_curve(e1.x(), e1.y())
p1 = client.new_plot()
p1.add(c1)

client.export_graphics_file("tmp.png")
27 changes: 27 additions & 0 deletions pyKst/demo/pykstplotdemo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python2.7
import pykstplot as plt
#import matplotlib.pyplot as plt
from numpy import *

x = linspace( -10, 10, 100)
y = sin(x)
z = cos(x)

plt.subplot(221)
plt.plot(x,y*y, linewidth=2, color = "green", linestyle="-.", label="greenline")
plt.subplot(122)
plt.plot(x,y,"k.")
plt.subplot(223)
plt.plot(x,z,"m*", markersize=6, color="blue")
plt.subplot(221, axisbg="lightblue")
plt.plot(x,z)
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.title("Title")

plt.figure()
plt.plot([1,3,7,15])

plt.show()

#plt.savefig("pltdemo.eps")
47 changes: 44 additions & 3 deletions pyKst/html/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ Until packaging (and the API) are settled, this may mean compiling kst2 from sou

pykst.py can use either PySide or PyQT4. Make sure one is installed, and edit the begining of pykst.py
accordingly (make sure the one you want to use is enabled, and the other is commented out.)
Then copy pykst.py into your systems python dir

Then run setup.py to install things properly. In linux this is::

sudo python2.7 setup.py install

PyKst depends on python2.7 or greater, and modern versions of NumPy and SciPy.

Examples
********
PyKst can be used control kst, as one would with the GUI. The following (minimal) example tells kst to
plot sin(x) from -10 to 10. The results are identical to having used create->equation from within kst.::
plot sin(x) from -10 to 10. The results are identical to having used create->equation from within kst::

import pykst as kst

Expand All @@ -35,7 +38,7 @@ plot sin(x) from -10 to 10. The results are identical to having used create->equ
p1 = client.new_plot()
p1.add(c1)

Alternatively, kst can be used to plot numpy arrays, as in this example::
kst can be also be used to plot numpy arrays, as in this example::

#!/usr/bin/python2.7
import pykst as kst
Expand All @@ -57,6 +60,39 @@ Alternatively, kst can be used to plot numpy arrays, as in this example::
p1 = client.new_plot()
p1.add(c1)

Alternativly, one can use a (tiny) subset of matplotlib.pyplot called pykstplot.
This interface is conceptually incompatible with the native interface, and is described
at the end of this document. As an example::

#!/usr/bin/python2.7
import pykstplot as plt
#import matplotlib.pyplot as plt
from numpy import *

x = linspace( -10, 10, 100)
y = sin(x)
z = cos(x)

plt.subplot(221)
plt.plot(x,y*y, linewidth=2, color = "green", linestyle="-.", label="greenline")
plt.subplot(122)
plt.plot(x,y,"k.")
plt.subplot(223)
plt.plot(x,z,"m*", markersize=6, color="blue")
plt.subplot(221, axisbg="lightblue")
plt.plot(x,z)
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.title("Title")

plt.figure()
plt.plot([1,3,7,15])

plt.show()

#plt.savefig("pltdemo.eps")

"

Clients
*******************
Expand Down Expand Up @@ -223,3 +259,8 @@ Interactive items are controls which are part of a kst view and use QtNetwork.QL
.. autoclass:: LineEdit
:members:
:inherited-members:

Pykstplot
*******************
.. automodule:: pykstplot
:members:
28 changes: 28 additions & 0 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ def save_kst_file(self, filename):
""" save a .kst file in kst. """
self.send("fileSave("+b2str(filename)+")")

def export_graphics_file(self, filename, format=None, width=1280, height=1024, display = 2):
"""
export the kst session as a set of graphics files.
:param filename: the name of the file to be saved
:param format: the format to be used. if None, the format is determined from the filename extension.
:param width: width of the plot, in pixels, if required by the display setting.
:param height: the height of the plot, in pixels, if required by the display setting.
:param display: how the dimensions are interpreted.
*display* determines the shape of the plot. Values are ::
0 Width set by user, maintain aspect ratio
1 Height set by user, maintain aspect ratio
2 Width and Height set by user.
3 a Width x Width square plot.
If there is more than one tab, each tab is in a separate file, named
filename_1.ext, etc.
"""

if format is None:
format = os.path.splitext(filename)[1][1:].strip().lower()

self.send("exportGraphics("+str(filename)+","+str(format)+","+str(width)+","+
str(height)+","+str(display)+")")


def screen_back(self):
""" Equivalent to "Range>Back One Screen" from the menubar inside kst. """
self.send("screenBack()")
Expand Down
Loading