gnuplot-snippets 0.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gnuplot_snippets/__init__.py +21 -0
- gnuplot_snippets/_utils.py +157 -0
- gnuplot_snippets/controller.py +484 -0
- gnuplot_snippets/demo.py +362 -0
- gnuplot_snippets/errors.py +13 -0
- gnuplot_snippets/snippets.py +519 -0
- gnuplot_snippets-0.1.5.dist-info/METADATA +222 -0
- gnuplot_snippets-0.1.5.dist-info/RECORD +11 -0
- gnuplot_snippets-0.1.5.dist-info/WHEEL +4 -0
- gnuplot_snippets-0.1.5.dist-info/entry_points.txt +3 -0
- gnuplot_snippets-0.1.5.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gnuplot-snippets
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Composable gnuplot snippets for Python, for interactive and batch plotting by advanced users
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Neil Temperley
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Dist: pandas (>=2.2.3)
|
|
16
|
+
Project-URL: Licence, https://github.com/neiltemperley/gnuplot-snippets/blob/main/LICENSE
|
|
17
|
+
Project-URL: Repository, https://github.com/neiltemperley/gnuplot-snippets
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# gnuplot-snippets
|
|
21
|
+
|
|
22
|
+
Composable gnuplot snippets for Python, for interactive and batch plotting by advanced users.
|
|
23
|
+
|
|
24
|
+
Tools for tightly integrating gnuplot with Python, enabling flexible
|
|
25
|
+
graph-by-graph interaction, interactive exploration, and batch
|
|
26
|
+
publishing — all from within Python.
|
|
27
|
+
|
|
28
|
+
Designed for gnuplot power users who need to visualize complex data
|
|
29
|
+
across different Python objects and classes with minimal gnuplot
|
|
30
|
+
rescripting per plot.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- Unrestricted access to gnuplot commands from Python.
|
|
35
|
+
- Minimal gnuplot code duplication across different plots.
|
|
36
|
+
- Gnuplot script logic resides primarily inside object classes.
|
|
37
|
+
- Native-feeling plot window interaction (as if running gnuplot directly).
|
|
38
|
+
- Interactive gradient and coordinate measurement via mouse.
|
|
39
|
+
- Batch-mode rendering for publication workflows.
|
|
40
|
+
- Logging and optional gnuplot stand-alone script dumping for debug and inspection.
|
|
41
|
+
- Python source markers in stand-alone scripts.
|
|
42
|
+
- Neat human-readable formatting of gnuplot datablocks and datafiles.
|
|
43
|
+
|
|
44
|
+
## Overview
|
|
45
|
+
|
|
46
|
+
Creating one-off plots from Python using existing gnuplot packages is
|
|
47
|
+
easy — but managing large, layered plots with data originating from
|
|
48
|
+
multiple classes is not. And Python packages often lack the same
|
|
49
|
+
interactive behavior that comes from launching a gnuplot session
|
|
50
|
+
directly.
|
|
51
|
+
|
|
52
|
+
Conversely, managing a large number of interactive and publication
|
|
53
|
+
plots solely using gnuplot script files results in large, complex files
|
|
54
|
+
that are difficult to navigate and manage.
|
|
55
|
+
|
|
56
|
+
This module addresses both issues by:
|
|
57
|
+
|
|
58
|
+
- Organizing reusable gnuplot script fragments.
|
|
59
|
+
- Re-enabling interactive plotting behaviors from Python.
|
|
60
|
+
- Introducing new interactive features (like mouse measurements).
|
|
61
|
+
- Enabling a "preview then publish" workflow across multiple plots.
|
|
62
|
+
|
|
63
|
+
The fundamental principle of snippets as implemented here is that each
|
|
64
|
+
object class should generate gnuplot scripts (snippets) to plot itself
|
|
65
|
+
on screen or to a file. To plot multiple objects on the same graph,
|
|
66
|
+
or to create a multiplot graph, those snippets are simply combined
|
|
67
|
+
with a minimum of additional gnuplot commands.
|
|
68
|
+
|
|
69
|
+
> **Note:** This package is *not intended for gnuplot beginners*. It assumes
|
|
70
|
+
> comfort with gnuplot syntax and behavior. It does *not* provide a
|
|
71
|
+
> simplified interface to gnuplot; rather, it gives experienced users
|
|
72
|
+
> unrestricted access to gnuplot from within Python.
|
|
73
|
+
|
|
74
|
+
## Background
|
|
75
|
+
|
|
76
|
+
I often work with multiple mathematical models, each represented by a
|
|
77
|
+
class with one or more `gnuplot_xxx()` methods. These models typically
|
|
78
|
+
generate gnuplot datablocks or multi-contour datafiles.
|
|
79
|
+
|
|
80
|
+
Things become complex when combining models, e.g. overlaying two
|
|
81
|
+
models with multiple axes, creating a multiplot, or using glorious
|
|
82
|
+
gnuplot constructs such as:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
plot \
|
|
86
|
+
for [i=1:nContoursModelA] "datafileModelA.dat" index i-1 using 1:(column("Performance_Gap")) axes x1y2 title sprintf("Model A, Contour=%d",aContoursModelA[i]) lw 2.5, \
|
|
87
|
+
for [i=1:nContoursModelB] "datafileModelB.dat" index i-1 using 1:(column("Performance_Gap")) axes x1y2 title sprintf("Model B, Contour=%d",aContoursModelB[i]) lw 2.5, \
|
|
88
|
+
$DataBlockModelC using 1:3 title "Model C" lw 2.5 dt 2
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This module provides Python-side containers for such gnuplot snippets,
|
|
92
|
+
allowing you to mix and match them to create plots with minimal script
|
|
93
|
+
duplication.
|
|
94
|
+
|
|
95
|
+
During model research and development, I often:
|
|
96
|
+
|
|
97
|
+
- Display plots interactively, one at a time, and publish PDF or
|
|
98
|
+
LaTeX versions as I go.
|
|
99
|
+
- Later switch to batch mode to render PDF or LaTeX-ready plots for publication.
|
|
100
|
+
|
|
101
|
+
This toolset was built to support that workflow. It won't do
|
|
102
|
+
everything for you — but it removes a lot of friction.
|
|
103
|
+
|
|
104
|
+
## Requirements
|
|
105
|
+
|
|
106
|
+
- Python 3.10 or newer
|
|
107
|
+
- [gnuplot](http://www.gnuplot.info/) installed and available on your `PATH`
|
|
108
|
+
- Tested with gnuplot 5.4 (check with `gnuplot --version`) on Linux.
|
|
109
|
+
|
|
110
|
+
## Installation
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install gnuplot-snippets
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To try it in a throwaway environment first:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
deactivate 2>/dev/null # exit any active environment
|
|
120
|
+
mkdir -p ~/tmp
|
|
121
|
+
cd ~/tmp
|
|
122
|
+
python3 -m venv ~/tmp/gp-snippets-test
|
|
123
|
+
source ~/tmp/gp-snippets-test/bin/activate
|
|
124
|
+
# On Windows: %USERPROFILE%\tmp\gp-snippets-test\Scripts\activate
|
|
125
|
+
python -m pip install --upgrade pip
|
|
126
|
+
pip install gnuplot-snippets
|
|
127
|
+
|
|
128
|
+
# Check it works:
|
|
129
|
+
pip show -f gnuplot-snippets
|
|
130
|
+
python -c "import gnuplot_snippets; print(gnuplot_snippets.__file__)"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Then run the demo (see [Full demo](#full-demo) below).
|
|
134
|
+
|
|
135
|
+
## Quick example
|
|
136
|
+
|
|
137
|
+
Provide a class a `gnuplot()` method that returns a `GnuplotSnippets`:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from gnuplot_snippets import GnuplotController, GnuplotSnippets
|
|
141
|
+
|
|
142
|
+
class Car:
|
|
143
|
+
|
|
144
|
+
def __init__(self, name, a, b, c):
|
|
145
|
+
self.name, self.a, self.b, self.c = name, a, b, c
|
|
146
|
+
|
|
147
|
+
def gnuplot(self) -> GnuplotSnippets:
|
|
148
|
+
gs = GnuplotSnippets()
|
|
149
|
+
gs.output_to_screen(
|
|
150
|
+
'set terminal qt title "Car Performance"',
|
|
151
|
+
'set xlabel "Time [s]"; set format x',
|
|
152
|
+
'set ylabel "Velocity [m/s]"; set format y "%0.1f"',
|
|
153
|
+
'set y2label "Acceleration [m/s^2]"; set format y2',
|
|
154
|
+
'set ytics nomirror; set y2tics',
|
|
155
|
+
show_source=True) # add source marker to script file
|
|
156
|
+
gs.preplot(
|
|
157
|
+
'fVelocity(t,a,b,c) = a*t**3 + b*t**2 + c*t',
|
|
158
|
+
'fAcceleration(t,a,b,c) = 3.*a*t**2 + 2.*b*t + c',
|
|
159
|
+
f'set title "Performance for {self.name}"',
|
|
160
|
+
show_source=True)
|
|
161
|
+
gs.plot_elements(
|
|
162
|
+
f'fVelocity(x,{self.a},{self.b},{self.c}) title "{self.name}" with lines',
|
|
163
|
+
f'fAcceleration(x,{self.a},{self.b},{self.c}) axis x1y2 title "{self.name} Acceleration" with lines',
|
|
164
|
+
)
|
|
165
|
+
gs.postplot('unset label')
|
|
166
|
+
return gs
|
|
167
|
+
|
|
168
|
+
gc = GnuplotController(script_filename="my_script.gp")
|
|
169
|
+
gs = Car("Car1", 0.01, 0.0001, 0.1).gnuplot()
|
|
170
|
+
|
|
171
|
+
# Note: Args to gc.preplot() are snippets or gnuplot commands.
|
|
172
|
+
# gs.preplot() returns the preplot() snippet string.
|
|
173
|
+
gc.preplot(gs.preplot(), "set xrange[0:15]", "set y2range[0:*]", gs.output_to_screen())
|
|
174
|
+
gc.plot(gs.plot_elements(), pause=4) # wait 4s
|
|
175
|
+
|
|
176
|
+
# Change title and repeat plot with interactive measurement:
|
|
177
|
+
gc.preplot(
|
|
178
|
+
'set title "Interactive Demo. \\nClick in this window, press \'m\' key, then click two points."'
|
|
179
|
+
)
|
|
180
|
+
gc.plot(gs.plot_elements(), pause="mouse_measure") # interactive
|
|
181
|
+
gc.postplot(gs.postplot())
|
|
182
|
+
gc.close()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Notes
|
|
186
|
+
|
|
187
|
+
- The example above uses the `qt` terminal. On Windows, switch to the
|
|
188
|
+
`windows` terminal (see the comment in the demo).
|
|
189
|
+
- Commands are sent to gnuplot in the order you pass them, so later `set`
|
|
190
|
+
commands override earlier ones, just like a normal gnuplot script.
|
|
191
|
+
- Here every command is also written to `my_script.gp`, so you can re-run or
|
|
192
|
+
debug it directly with `gnuplot my_script.gp`.
|
|
193
|
+
|
|
194
|
+
## Full demo
|
|
195
|
+
|
|
196
|
+
The full demo covers plotting to the screen, publishing to a PDF, overlaying
|
|
197
|
+
two objects on one graph, and using the controller directly without snippets
|
|
198
|
+
(including the interactive `mouse_measure` pause). Use it as a template to
|
|
199
|
+
get started.
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
python -m gnuplot_snippets.demo
|
|
203
|
+
# OR:
|
|
204
|
+
gnuplot-snippets-demo
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Demo source: https://github.com/neiltemperley/gnuplot-snippets/blob/main/src/gnuplot_snippets/demo.py
|
|
208
|
+
|
|
209
|
+
## Security
|
|
210
|
+
|
|
211
|
+
Snippets are passed to gnuplot verbatim, and gnuplot can run shell commands
|
|
212
|
+
(e.g. via `system`) and write files. Never build snippets from untrusted
|
|
213
|
+
input, and choose safe filenames for script and output files.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
Released under the [MIT License](https://github.com/neiltemperley/gnuplot-snippets/blob/main/LICENSE).
|
|
218
|
+
|
|
219
|
+
## Disclaimer
|
|
220
|
+
|
|
221
|
+
This is an unofficial project and is not affiliated with gnuplot.
|
|
222
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
gnuplot_snippets/__init__.py,sha256=BaDTvdWXV5IWCAXjnXWWElWrRf7RaCZuASOZ_R7lfm4,769
|
|
2
|
+
gnuplot_snippets/_utils.py,sha256=rLVSGRy638lBttUYR_gplSUXDJLVkEyOhQ1LK9LLJag,6088
|
|
3
|
+
gnuplot_snippets/controller.py,sha256=CMJIkgm-AXFrItlkyGqymgv3EZ4DFXaPxlS8Db1ryAA,22200
|
|
4
|
+
gnuplot_snippets/demo.py,sha256=wqTSINV4Hhai-mGU7f0JiHOIGJc3_2nzvAhHVXl1-B8,16378
|
|
5
|
+
gnuplot_snippets/errors.py,sha256=MSpCsIVdNY_JqKgiLnNfg8tJ0-rW12vU4tpPw2Q2VnU,483
|
|
6
|
+
gnuplot_snippets/snippets.py,sha256=eJL_NWeqWIawUJw0laQya4mFBltvZrmN21-1PWmPrKc,24100
|
|
7
|
+
gnuplot_snippets-0.1.5.dist-info/METADATA,sha256=AduiIqpbsDsSlB9B0mULhevHyKOJZZ2zHT939ypTEEI,8373
|
|
8
|
+
gnuplot_snippets-0.1.5.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
9
|
+
gnuplot_snippets-0.1.5.dist-info/entry_points.txt,sha256=r7D2RHre11pi2Z8SX3mbDIRL1JWo5q2ZqPBV7uK9czQ,68
|
|
10
|
+
gnuplot_snippets-0.1.5.dist-info/licenses/LICENSE,sha256=k4790LL2OxZCY7s63uh7Tjcriq8sVrNFNP8KpXewwGs,1076
|
|
11
|
+
gnuplot_snippets-0.1.5.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Neil Temperley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|