Skip to content

Commit a36dc2b

Browse files
committed
README.org shows graphical figures
1 parent 1a9066b commit a36dc2b

8 files changed

+4449
-8
lines changed

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

+862
Loading

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

+302
Loading

README.org

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import gnuplotlib as gp
1212

1313
x = np.arange(101) - 50
1414
gp.plot(x**2)
15-
[ basic parabola plot pops up ]
15+
#+END_SRC
16+
[[file:basic-parabola-plot-pops-up.svg]]
17+
#+BEGIN_SRC python
1618

1719

1820
g1 = gp.gnuplotlib(title = 'Parabola with error bars',
1921
_with = 'xyerrorbars')
2022
g1.plot( x**2 * 10, np.abs(x)/10, np.abs(x)*5,
2123
legend = 'Parabola',
2224
tuplesize = 4 )
23-
[ parabola with x,y errobars pops up in a new window ]
25+
#+END_SRC
26+
[[file:parabola-with-x-y-errobars-pops-up-in-a-new-window.svg]]
27+
#+BEGIN_SRC python
2428

2529

2630
x,y = np.ogrid[-10:11,-10:11]
@@ -30,7 +34,9 @@ gp.plot( x**2 + y**2,
3034
cmds = 'set view map',
3135
_with = 'image',
3236
tuplesize = 3)
33-
[ Heat map pops up where first parabola used to be ]
37+
#+END_SRC
38+
[[file:Heat-map-pops-up-where-first-parabola-used-to-be.svg]]
39+
#+BEGIN_SRC python
3440

3541

3642
theta = np.linspace(0, 6*np.pi, 200)
@@ -39,22 +45,28 @@ g2 = gp.gnuplotlib(_3d = True)
3945
g2.plot( np.cos(theta),
4046
np.vstack((np.sin(theta), -np.sin(theta))),
4147
z )
42-
[ Two 3D spirals together in a new window ]
48+
#+END_SRC
49+
[[file:Two-3D-spirals-together-in-a-new-window.svg]]
50+
#+BEGIN_SRC python
4351

4452

4553
x = np.arange(1000)
4654
gp.plot( (x*x, dict(histogram=1,
4755
binwidth =10000)),
4856
(x*x, dict(histogram='cumulative', y2=1)))
49-
[ A density and cumulative histogram of x^2 are plotted on the same plot ]
57+
#+END_SRC
58+
[[file:A-density-and-cumulative-histogram-of-x-2-are-plotted-on-the-same-plot.svg]]
59+
#+BEGIN_SRC python
5060

5161
gp.plot( (x*x, dict(histogram=1,
5262
binwidth =10000)),
5363
(x*x, dict(histogram='cumulative')),
5464
_xmin=0, _xmax=1e6,
5565
multiplot='title "multiplot histograms" layout 2,1',
5666
_set='lmargin at screen 0.05')
57-
[ Same histograms, but plotted on two separate plots ]
67+
#+END_SRC
68+
[[file:Same-histograms-but-plotted-on-two-separate-plots.svg]]
69+
#+BEGIN_SRC python
5870
#+END_SRC
5971

6072
* DESCRIPTION

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

+1,136
Loading

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

+887
Loading

basic-parabola-plot-pops-up.svg

+334
Loading

extract_README.py

+79-2
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,22 @@ 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+
if in_quote is not None:
158+
if in_quote == 'example': f.write('#+END_EXAMPLE\n')
159+
else: f.write('#+END_SRC\n')
160+
f.write(f"[[file:{plot_filename}]]\n")
161+
if in_quote is not None:
162+
if in_quote == 'example': f.write('#+BEGIN_EXAMPLE\n')
163+
else: f.write('#+BEGIN_SRC python\n')
164+
continue
165+
89166
# handle links
90167
l = re.sub( r"([^ ]+) *\((https?://[^ ]+)\)",
91168
r"[[\2][\1]]",

0 commit comments

Comments
 (0)