Warning, /graphics/kst-plot/pyKst/html/index.rst is written in an unsupported language. File is not indexed.
0001 .. toctree::
0002 :maxdepth: 2
0003
0004 PyKst documentation
0005 =================================
0006 PyKst is a python interface to kst. With PyKst, scripts can control and share data with a kst session.
0007
0008 Installation
0009 ************
0010 You will want the version of pykst.py that goes with your version of kst2.
0011 Until packaging (and the API) are settled, this may mean compiling kst2 from source.
0012
0013 pykst.py can use either PySide or PyQT4. Make sure one is installed, and edit the begining of pykst.py
0014 accordingly (make sure the one you want to use is enabled, and the other is commented out.)
0015
0016 Then run setup.py to install things properly. In linux this is::
0017
0018 sudo python2.7 setup.py install
0019
0020 PyKst depends on python2.7 or greater, and modern versions of NumPy and SciPy.
0021
0022 Examples
0023 ********
0024 PyKst can be used control kst, as one would with the GUI. The following (minimal) example tells kst to
0025 plot sin(x) from -10 to 10. The results are identical to having used create->equation from within kst::
0026
0027 import pykst as kst
0028
0029 # start a kst session with the arbitrary name "TestSinX"
0030 client=kst.Client("TestSinX")
0031
0032 # inside kst, create the x vector and the equation
0033 v1 = client.new_generated_vector(-10, 10, 1000)
0034 e1 = client.new_equation(v1, "sin(x)")
0035
0036 # inside kst, create a curve, a plot, and add the curve to the plot
0037 c1 = client.new_curve(e1.x(), e1.y())
0038 p1 = client.new_plot()
0039 p1.add(c1)
0040
0041 kst can be also be used to plot numpy arrays, as in this example::
0042
0043 #!/usr/bin/python2.7
0044 import pykst as kst
0045 import numpy as np
0046
0047 # create a pair of numpy arrays
0048 x = np.linspace( -10, 10, 1000)
0049 y = np.sin(x)
0050
0051 # start a kst session with the arbitrary name "NumpyVector"
0052 client=kst.Client("NumpyVector")
0053
0054 # copy the numpy arrays into kst
0055 V1 = client.new_editable_vector(x, name="X") # the name is for the label
0056 V2 = client.new_editable_vector(y, name="sin(X)") # the name is for the label
0057
0058 # inside kst, create a curve, a plot, and add the curve to the plot
0059 c1 = client.new_curve(V1, V2)
0060 p1 = client.new_plot()
0061 p1.add(c1)
0062
0063 Alternativly, one can use a (tiny) subset of matplotlib.pyplot called pykstplot.
0064 This interface is conceptually incompatible with the native interface, and is described
0065 at the end of this document. As an example::
0066
0067 #!/usr/bin/python2.7
0068 import pykstplot as plt
0069 #import matplotlib.pyplot as plt
0070 import numpy as np
0071
0072 x = np.linspace( -10, 10, 100)
0073 y = np.sin(x)
0074 z = np.cos(x)
0075
0076 plt.subplot(221)
0077 plt.plot(x,y*y, linewidth=2, color = "green", linestyle="-.", label="greenline")
0078 plt.subplot(122)
0079 plt.plot(x,y,"k.")
0080 plt.subplot(223)
0081 plt.plot(x,z,"m*", markersize=6, color="blue")
0082 plt.subplot(221, axisbg="lightblue")
0083 plt.plot(x,z)
0084 plt.xlabel("X axis")
0085 plt.ylabel("Y axis")
0086 plt.title("Title")
0087
0088 plt.figure()
0089 plt.plot([1,3,7,15])
0090
0091 plt.show()
0092
0093 #plt.savefig("pltdemo.eps")
0094
0095 "
0096
0097 Clients
0098 *******************
0099 .. automodule:: pykst
0100 :members: Client
0101 :exclude-members: getArray, getList, send
0102
0103 Primitives
0104 **********
0105 Scalars, Vectors, Matrices, and Strings (Primitives) can be used in
0106 your scripts to share data with kst. All methods are pass-by-value:
0107 for example, if you get a value of a scalar and change it, the data
0108 inside kst is not changed. You need to explicitly call setValue().
0109
0110 Scalars
0111 -------
0112 .. autoclass:: DataSourceScalar
0113 :members:
0114 :inherited-members:
0115
0116 .. autoclass:: VectorScalar
0117 :members:
0118 :inherited-members:
0119
0120 .. autoclass:: GeneratedScalar
0121 :members:
0122 :inherited-members:
0123
0124
0125 Vectors
0126 -------
0127 .. autoclass:: DataVector
0128 :members:
0129 :inherited-members:
0130
0131 .. autoclass:: GeneratedVector
0132 :members:
0133 :inherited-members:
0134
0135 .. autoclass:: EditableVector
0136 :members:
0137 :inherited-members:
0138
0139
0140 Matrices
0141 ---------
0142 .. autoclass:: DataMatrix
0143 :members:
0144 :inherited-members:
0145
0146
0147 Strings
0148 -------
0149 .. autoclass:: DataSourceString
0150 :members:
0151 :inherited-members:
0152 :exclude-members: setValue
0153
0154 .. autoclass:: GeneratedString
0155 :members:
0156 :inherited-members:
0157
0158 Data Objects
0159 ************
0160 Data Objects are objects which transform primitives into other
0161 primitives.
0162
0163 Equations
0164 ---------
0165 .. autoclass:: Equation
0166 :members:
0167 :inherited-members:
0168
0169 Spectra
0170 -------
0171 .. autoclass:: Spectrum
0172 :members:
0173 :inherited-members:
0174
0175 Histograms
0176 ----------
0177 .. autoclass:: Histogram
0178 :members:
0179 :inherited-members:
0180
0181 Linear Fit
0182 ----------
0183 .. autoclass:: LinearFit
0184 :members:
0185 :inherited-members:
0186
0187 Polynomial Fit
0188 --------------
0189 .. autoclass:: PolynomialFit
0190 :members:
0191 :inherited-members:
0192
0193 Flag Filter
0194 --------------
0195 .. autoclass:: FlagFilter
0196 :members:
0197 :inherited-members:
0198
0199 Relations
0200 *********
0201 Relations are objects which can be added to a plot.
0202
0203 Curves
0204 ------
0205 .. autoclass:: Curve
0206 :members:
0207 :inherited-members:
0208
0209 Images
0210 ------
0211 .. autoclass:: Image
0212 :members:
0213 :inherited-members:
0214
0215 Annotations
0216 ***********
0217 Annotations along with interactive items (see the next section) can be used to turn kst into a graphing calculator, a tetris client, and maybe even a web browser...
0218
0219 .. autoclass:: Label
0220 :members:
0221 :inherited-members:
0222 :exclude-members: set_fill_color, set_fill_style, set_stroke_style, set_stroke_width, set_stroke_brush_color, set_stroke_brush_style, set_stroke_join_style, set_stroke_cap_style, set_fixed_aspect_ratio, set_size
0223 .. autoclass:: Legend
0224 :members:
0225 :inherited-members:
0226 :exclude-members: set_fixed_aspect_ratio, set_size
0227 .. autoclass:: Box
0228 :members:
0229 :inherited-members:
0230
0231 .. autoclass:: Circle
0232 :members:
0233 :inherited-members:
0234 :exclude-members: set_stroke_join_style, set_stroke_cap_style, set_fixed_aspect_ratio, set_size
0235
0236 .. autoclass:: Ellipse
0237 :members:
0238 :inherited-members:
0239 :exclude-members: set_stroke_join_style, set_stroke_cap_style
0240
0241 .. autoclass:: Line
0242 :members:
0243 :inherited-members:
0244 :exclude-members: set_fill_color, set_fill_style, set_stroke_join_style, set_fixed_aspect_ratio, set_size
0245
0246 .. autoclass:: Arrow
0247 :members:
0248 :inherited-members:
0249 :exclude-members: set_fill_color, set_fill_style, set_stroke_join_style, set_fixed_aspect_ratio, set_size
0250
0251 .. autoclass:: Picture
0252 :members:
0253 :inherited-members:
0254 :exclude-members: set_fill_color, set_fill_style, set_stroke_style, set_stroke_width, set_stroke_brush_color, set_stroke_brush_style, set_stroke_join_style, set_stroke_cap_style
0255
0256 .. autoclass:: SVG
0257 :members:
0258 :inherited-members:
0259 :exclude-members: set_fill_color, set_fill_style, set_stroke_style, set_stroke_width, set_stroke_brush_color, set_stroke_brush_style, set_stroke_join_style, set_stroke_cap_style
0260
0261 .. autoclass:: Plot
0262 :members:
0263 :inherited-members:
0264
0265 Interactive items
0266 *****************
0267 Interactive items are controls which are part of a kst view and use QtNetwork.QLocalSocket to notify the script when the user has interacted with them. They can only be created through scripts.
0268
0269 .. autoclass:: Button
0270 :members:
0271 :inherited-members:
0272
0273 .. autoclass:: LineEdit
0274 :members:
0275 :inherited-members:
0276
0277 Pykstplot
0278 *********
0279 pykstplot re-implements a tiny subset of matplotlib.pyplot. It is included by importing pykstplot,
0280 and is conceptually incompatible with pykst.
0281
0282 .. automodule:: pykstplot
0283 :members: