Skip to content

Commit 05da734

Browse files
committed
README.org shows graphical figures
1 parent d23b82b commit 05da734

8 files changed

+4431
-8
lines changed

A-density-and-cumulative-histogram-of-x-2-are-plotted-on-the-same-plot.svg

Lines changed: 862 additions & 0 deletions
Loading

Heat-map-pops-up-where-first-parabola-used-to-be.svg

Lines changed: 302 additions & 0 deletions
Loading

README.org

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import gnuplotlib as gp
1212

1313
x = np.arange(101) - 50
1414
gp.plot(x**2)
15-
[ basic parabola plot pops up ]
15+
[[file:basic-parabola-plot-pops-up.svg]]
1616

1717

1818
g1 = gp.gnuplotlib(title = 'Parabola with error bars',
1919
_with = 'xyerrorbars')
2020
g1.plot( x**2 * 10, np.abs(x)/10, np.abs(x)*5,
2121
legend = 'Parabola',
2222
tuplesize = 4 )
23-
[ parabola with x,y errobars pops up in a new window ]
23+
[[file:parabola-with-x-y-errobars-pops-up-in-a-new-window.svg]]
2424

2525

2626
x,y = np.ogrid[-10:11,-10:11]
@@ -30,7 +30,7 @@ gp.plot( x**2 + y**2,
3030
cmds = 'set view map',
3131
_with = 'image',
3232
tuplesize = 3)
33-
[ Heat map pops up where first parabola used to be ]
33+
[[file:Heat-map-pops-up-where-first-parabola-used-to-be.svg]]
3434

3535

3636
theta = np.linspace(0, 6*np.pi, 200)
@@ -39,22 +39,22 @@ g2 = gp.gnuplotlib(_3d = True)
3939
g2.plot( np.cos(theta),
4040
np.vstack((np.sin(theta), -np.sin(theta))),
4141
z )
42-
[ Two 3D spirals together in a new window ]
42+
[[file:Two-3D-spirals-together-in-a-new-window.svg]]
4343

4444

4545
x = np.arange(1000)
4646
gp.plot( (x*x, dict(histogram=1,
4747
binwidth =10000)),
4848
(x*x, dict(histogram='cumulative', y2=1)))
49-
[ A density and cumulative histogram of x^2 are plotted on the same plot ]
49+
[[file:A-density-and-cumulative-histogram-of-x-2-are-plotted-on-the-same-plot.svg]]
5050

5151
gp.plot( (x*x, dict(histogram=1,
5252
binwidth =10000)),
5353
(x*x, dict(histogram='cumulative')),
5454
_xmin=0, _xmax=1e6,
5555
multiplot='title "multiplot histograms" layout 2,1',
5656
_set='lmargin at screen 0.05')
57-
[ Same histograms, but plotted on two separate plots ]
57+
[[file:Same-histograms-but-plotted-on-two-separate-plots.svg]]
5858
#+END_SRC
5959

6060
* DESCRIPTION

Same-histograms-but-plotted-on-two-separate-plots.svg

Lines changed: 1136 additions & 0 deletions
Loading

Two-3D-spirals-together-in-a-new-window.svg

Lines changed: 887 additions & 0 deletions
Loading

basic-parabola-plot-pops-up.svg

Lines changed: 334 additions & 0 deletions
Loading

extract_README.py

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,76 @@
1111
- README.footer.org, copied verbatim
1212
1313
The main module name must be passed in as the first cmdline argument.
14+
15+
If we want to regenerate the figures linked in the README.org documentation,
16+
pass "DOCUMENTATION-PLOTS" as the first argument
17+
1418
'''
1519

1620
import sys
21+
import os.path
22+
23+
def generate_plots():
24+
r'''Makes plots in the docstring of the gnuplotlib.py module'''
25+
26+
import numpy as np
27+
import gnuplotlib as gp
28+
29+
x = np.arange(101) - 50
30+
gp.plot(x**2,
31+
hardcopy='basic-parabola-plot-pops-up.svg')
32+
33+
g1 = gp.gnuplotlib(title = 'Parabola with error bars',
34+
_with = 'xyerrorbars',
35+
hardcopy = 'parabola-with-x-y-errobars-pops-up-in-a-new-window.svg')
36+
g1.plot( x**2 * 10, np.abs(x)/10, np.abs(x)*5,
37+
legend = 'Parabola',
38+
tuplesize = 4 )
39+
40+
x,y = np.ogrid[-10:11,-10:11]
41+
gp.plot( x**2 + y**2,
42+
title = 'Heat map',
43+
unset = 'grid',
44+
cmds = 'set view map',
45+
_with = 'image',
46+
tuplesize = 3,
47+
hardcopy = 'Heat-map-pops-up-where-first-parabola-used-to-be.svg')
48+
49+
theta = np.linspace(0, 6*np.pi, 200)
50+
z = np.linspace(0, 5, 200)
51+
g2 = gp.gnuplotlib(_3d = True,
52+
hardcopy = 'Two-3D-spirals-together-in-a-new-window.svg')
53+
g2.plot( np.cos(theta),
54+
np.vstack((np.sin(theta), -np.sin(theta))),
55+
z )
56+
57+
x = np.arange(1000)
58+
gp.plot( (x*x, dict(histogram=1,
59+
binwidth =10000)),
60+
(x*x, dict(histogram='cumulative', y2=1)),
61+
hardcopy = 'A-density-and-cumulative-histogram-of-x-2-are-plotted-on-the-same-plot.svg' )
62+
63+
gp.plot( (x*x, dict(histogram=1,
64+
binwidth =10000)),
65+
(x*x, dict(histogram='cumulative')),
66+
_xmin=0, _xmax=1e6,
67+
multiplot='title "multiplot histograms" layout 2,1',
68+
_set='lmargin at screen 0.05',
69+
hardcopy = 'Same-histograms-but-plotted-on-two-separate-plots.svg')
70+
71+
1772

1873
try:
19-
modname = sys.argv[1]
74+
arg1 = sys.argv[1]
2075
except:
21-
raise Exception("Need main module name as the first cmdline arg")
76+
raise Exception("Need main module name or 'DOCUMENTATION-PLOTS' as the first cmdline arg")
2277

78+
if arg1 == 'DOCUMENTATION-PLOTS':
79+
generate_plots()
80+
sys.exit(0)
81+
82+
83+
modname = arg1
2384
exec( 'import {} as mod'.format(modname) )
2485

2586
import inspect
@@ -86,6 +147,16 @@ def write(s, verbatim):
86147
sio = StringIO(s)
87148
for l in sio:
88149

150+
# if we have a figure made with DOCUMENTATION-PLOTS, place it
151+
m = re.match(r'^ \[ (.*) \]$', l)
152+
if m is not None:
153+
tag = m.group(1)
154+
tag = re.sub(r'[^a-zA-Z0-9_]+','-', tag)
155+
plot_filename = f"{tag}.svg"
156+
if os.path.isfile(plot_filename):
157+
f.write(f"[[file:{plot_filename}]]\n")
158+
continue
159+
89160
# handle links
90161
l = re.sub( r"([^ ]+) *\((https?://[^ ]+)\)",
91162
r"[[\2][\1]]",

0 commit comments

Comments
 (0)