Skip to content

Commit 2c790fa

Browse files
committed
flake8ed
1 parent 941d982 commit 2c790fa

5 files changed

Lines changed: 232 additions & 221 deletions

File tree

Doc/xmgrace_tutorial_Numeric.py

Lines changed: 106 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,118 +9,121 @@
99
TEMPDIR = './'
1010

1111
# First let's create some data
12-
npoints=50
13-
X=numpy.arrayrange(npoints,dtype='d')
14-
X=X/float(npoints)*2.*numpy.pi
12+
npoints = 50
13+
X = numpy.arrayrange(npoints, dtype='d')
14+
X = X / float(npoints) * 2. * numpy.pi
1515

16-
Y1=numpy.ma.sin(X)
17-
Y2=numpy.ma.cos(X)
18-
Y3=numpy.ma.tan(X)
16+
Y1 = numpy.ma.sin(X)
17+
Y2 = numpy.ma.cos(X)
18+
Y3 = numpy.ma.tan(X)
1919

20-
# Now the real grace thing, plot the 2 on one graph and the diff on another graph
20+
# Now the real grace thing, plot the 2 on one graph and the diff on
21+
# another graph
2122

22-
from genutil import xmgrace # first we need to import xmgrace module
23+
from genutil import xmgrace # first we need to import xmgrace module
2324

24-
x=xmgrace.init() # create our xmgrace object
25+
x = xmgrace.init() # create our xmgrace object
2526

2627
# First let's set our graphs area
2728
# graph 0, exist by default, but we need to add 1 graph, therefore:
28-
x.add_graph() # adds one graph to our graph list (x.Graph)
29+
x.add_graph() # adds one graph to our graph list (x.Graph)
2930

3031
# Let's change the orientation of the page to portrait
3132
x.portrait()
3233

3334
# Now let's set the area of graph 0
34-
x.Graph[0].vymin=.55 # starts at 55% of the page
35-
x.Graph[0].vymax=.9 # stops at 90% of the page
36-
x.Graph[0].vxmin=.1 # starts at 10% of the page
37-
x.Graph[0].vxmax=.75 # stops at 75% of the page
35+
x.Graph[0].vymin = .55 # starts at 55% of the page
36+
x.Graph[0].vymax = .9 # stops at 90% of the page
37+
x.Graph[0].vxmin = .1 # starts at 10% of the page
38+
x.Graph[0].vxmax = .75 # stops at 75% of the page
3839
# and the area of graph 1
39-
x.Graph[1].vymin=.1 # starts at 10% of the page
40-
x.Graph[1].vymax=.45 # 45 % of page
40+
x.Graph[1].vymin = .1 # starts at 10% of the page
41+
x.Graph[1].vymax = .45 # 45 % of page
4142
# Let's offset the 2 graphs just for fun
42-
x.Graph[1].vxmin=.25 # starts at 55% of the page
43-
x.Graph[1].vxmax=.9 # stops at 90% of the page
43+
x.Graph[1].vxmin = .25 # starts at 55% of the page
44+
x.Graph[1].vxmax = .9 # stops at 90% of the page
4445

4546
# let's set the titles and subtitles
46-
x.Graph[0].title='TRIGO'
47-
x.Graph[0].stitle='SIN and COS'
48-
x.Graph[1].stitle='TAN'
47+
x.Graph[0].title = 'TRIGO'
48+
x.Graph[0].stitle = 'SIN and COS'
49+
x.Graph[1].stitle = 'TAN'
4950

5051

5152
# ok now let's set the min ans max for the Yaxis
52-
x.Graph[0].yaxis.min=-1. # ymin for graph 0
53-
x.Graph[0].yaxis.max=1. # ymax for graph 0
54-
x.Graph[1].yaxis.min=-1.5 # ymin for graph 1
55-
x.Graph[1].yaxis.max=1.5 # ymax for graph 1
53+
x.Graph[0].yaxis.min = -1. # ymin for graph 0
54+
x.Graph[0].yaxis.max = 1. # ymax for graph 0
55+
x.Graph[1].yaxis.min = -1.5 # ymin for graph 1
56+
x.Graph[1].yaxis.max = 1.5 # ymax for graph 1
5657

5758
# Now let's set the tick marks for Graph 0
58-
x.Graph[0].yaxis.tick.inc=1 # Main tick every unit
59-
x.Graph[0].yaxis.tick.minor_ticks=4 # 4 sub in between , 1 every .25 units
59+
x.Graph[0].yaxis.tick.inc = 1 # Main tick every unit
60+
x.Graph[0].yaxis.tick.minor_ticks = 4 # 4 sub in between , 1 every .25 units
6061
# Now let's set the tick marks for Graph 1
61-
x.Graph[1].yaxis.tick.inc=10 # Main tick every 10
62-
x.Graph[1].yaxis.tick.minor_ticks=4 # 4 sub in between , 1 every 2.5 units
62+
x.Graph[1].yaxis.tick.inc = 10 # Main tick every 10
63+
x.Graph[1].yaxis.tick.minor_ticks = 4 # 4 sub in between , 1 every 2.5 units
6364

6465
# X values are between 0 and 2pi
6566
# therefore let's set the axis from -1,1
66-
x.Graph[0].xaxis.min=0.
67-
x.Graph[0].xaxis.max=2.*numpy.pi
68-
x.Graph[1].xaxis.min=0.
69-
x.Graph[1].xaxis.max=2.*numpy.pi
70-
71-
# Set the xaxis ticks
72-
dic={0.:'0',numpy.pi/2:'PI/2',numpy.pi:'PI',3*numpy.pi/2:'3PI/2',2*numpy.pi:'2PI'}
73-
x.Graph[0].xaxis.tick.spec.loc=dic
67+
x.Graph[0].xaxis.min = 0.
68+
x.Graph[0].xaxis.max = 2. * numpy.pi
69+
x.Graph[1].xaxis.min = 0.
70+
x.Graph[1].xaxis.max = 2. * numpy.pi
71+
72+
# Set the xaxis ticks
73+
dic = {0.: '0', numpy.pi / 2: 'PI/2', numpy.pi: 'PI',
74+
3 * numpy.pi / 2: '3PI/2', 2 * numpy.pi: '2PI'}
75+
x.Graph[0].xaxis.tick.spec.loc = dic
7476
# way 2 the "less convential" way
75-
x.Graph[1].xaxis.tick.spec.loc=dic
77+
x.Graph[1].xaxis.tick.spec.loc = dic
7678
# Finally let's reduce the size a bit
77-
x.Graph[0].xaxis.tick.label.char_size=.8
78-
x.Graph[1].xaxis.tick.label.char_size=.8
79+
x.Graph[0].xaxis.tick.label.char_size = .8
80+
x.Graph[1].xaxis.tick.label.char_size = .8
7981

8082
# Ok now the legend
81-
x.Graph[0].legend.char_size=.8
82-
x.Graph[0].legend.x=.8 # Legend at 80% in x
83-
x.Graph[0].legend.x=.8 # Legend at 80% in y
84-
#or
85-
x.Graph[1].legend.char_size=.8
86-
x.Graph[1].legend.x=.05
87-
x.Graph[1].legend.y=.35
83+
x.Graph[0].legend.char_size = .8
84+
x.Graph[0].legend.x = .8 # Legend at 80% in x
85+
x.Graph[0].legend.x = .8 # Legend at 80% in y
86+
# or
87+
x.Graph[1].legend.char_size = .8
88+
x.Graph[1].legend.x = .05
89+
x.Graph[1].legend.y = .35
8890

8991
# Ok now let's play with the appearence of the sets themself
9092
# Ok by default we only have 2 sets (1 per graph)
9193
# So we need to add 2 sets
92-
x.add_set(0) # adding to graph 0 (since it's graph 0, the 0 is optional)
94+
x.add_set(0) # adding to graph 0 (since it's graph 0, the 0 is optional)
9395

9496
# First let's change the line width
95-
x.Graph[0].Set[0].line.linewidth=2
96-
x.Graph[0].Set[1].line.linewidth=2
97-
x.Graph[1].Set[0].line.linewidth=2
97+
x.Graph[0].Set[0].line.linewidth = 2
98+
x.Graph[0].Set[1].line.linewidth = 2
99+
x.Graph[1].Set[0].line.linewidth = 2
98100
# Let's set the colors
99-
x.Graph[0].Set[0].line.color='red' # xmgrace default colors are coded
100-
x.Graph[0].Set[1].line.color=4 # color 4 is blue
101+
x.Graph[0].Set[0].line.color = 'red' # xmgrace default colors are coded
102+
x.Graph[0].Set[1].line.color = 4 # color 4 is blue
101103
# Let's define a new color for the tangeante
102104
x.add_color('purple')
103-
x.Graph[1].Set[0].line.color='purple' # use the color we just defined
105+
x.Graph[1].Set[0].line.color = 'purple' # use the color we just defined
104106
# Let's set the second's set style to dash
105-
x.Graph[1].Set[0].line.linestyle='solid'
106-
x.Graph[0].Set[1].line.linestyle='dash'
107-
x.Graph[0].Set[0].line.linestyle=2 # 2 is dot
107+
x.Graph[1].Set[0].line.linestyle = 'solid'
108+
x.Graph[0].Set[1].line.linestyle = 'dash'
109+
x.Graph[0].Set[0].line.linestyle = 2 # 2 is dot
108110

109111
# Now let's set the name for each set, to be used in the legend
110-
x.Graph[0].Set[0].legend='SIN'
111-
x.Graph[0].Set[1].legend='COS'
112-
x.Graph[1].Set[0].legend='TAN'
112+
x.Graph[0].Set[0].legend = 'SIN'
113+
x.Graph[0].Set[1].legend = 'COS'
114+
x.Graph[1].Set[0].legend = 'TAN'
113115
# ok one last trick, in order to have the 0 line plotted
114116
# let's create a dummy array with zeros in it:
115-
zero=[0,0]
117+
zero = [0, 0]
116118
# add a dataset and assign it graph 1 black color
117-
x.add_set(1,'black')
119+
x.add_set(1, 'black')
118120

119121
# Finally just for fun let's place a big red "Sample" accross it
120-
x.add_string(0.5,0.5,'Sample',color='red',char_size=9,rot=55,just=14)
122+
x.add_string(0.5, 0.5, 'Sample', color='red', char_size=9, rot=55, just=14)
121123

122124
# And plot these babies:
123-
x.plot([Y1,Y2,Y3,zero],xs=[X,X,X,[0.,2.*numpy.pi]]) # You MUST pass a list of slab, even if only one slab
125+
# You MUST pass a list of slab, even if only one slab
126+
x.plot([Y1, Y2, Y3, zero], xs=[X, X, X, [0., 2. * numpy.pi]])
124127
# or you can plot then 1 by 1
125128
# first let's clear
126129
x('kill G0.S0')
@@ -130,48 +133,51 @@
130133

131134
# Now the tan is pretty ugly because of extreme let's mask everything
132135
# that is greater than 1.5 and redraw that
133-
Y3=numpy.ma.masked_greater(Y3,1.5)
136+
Y3 = numpy.ma.masked_greater(Y3, 1.5)
134137

135138
# Also we're going to add error bars 10% of the value
136139
# dx for the sin
137-
YY1=numpy.ma.zeros((2,npoints),dtype='d')
138-
YY1[0]=Y1
139-
YY1[1]=Y1*.1
140-
x.Graph[0].Set[0].type='xydx'
141-
x.Graph[0].Set[0].errorbar.status='on'
142-
x.Graph[0].Set[0].errorbar.color='red'
140+
YY1 = numpy.ma.zeros((2, npoints), dtype='d')
141+
YY1[0] = Y1
142+
YY1[1] = Y1 * .1
143+
x.Graph[0].Set[0].type = 'xydx'
144+
x.Graph[0].Set[0].errorbar.status = 'on'
145+
x.Graph[0].Set[0].errorbar.color = 'red'
143146
# dy for the cos
144-
YY2=numpy.ma.zeros((2,npoints),dtype='d')
145-
YY2[0]=Y2
146-
YY2[1]=Y2*.1
147-
x.Graph[0].Set[1].type='xydy'
148-
x.Graph[0].Set[1].errorbar.status='on'
149-
x.Graph[0].Set[1].errorbar.color=x.Graph[0].Set[1].line.color
147+
YY2 = numpy.ma.zeros((2, npoints), dtype='d')
148+
YY2[0] = Y2
149+
YY2[1] = Y2 * .1
150+
x.Graph[0].Set[1].type = 'xydy'
151+
x.Graph[0].Set[1].errorbar.status = 'on'
152+
x.Graph[0].Set[1].errorbar.color = x.Graph[0].Set[1].line.color
150153
# dy and dx for the tan
151-
YY3=numpy.ma.zeros((3,npoints),dtype='d')
152-
YY3[0]=Y3
153-
YY3[1]=Y3*.1
154-
YY3[2]=Y3*.1
155-
x.Graph[1].Set[0].type='xydxdy'
156-
x.Graph[1].Set[0].errorbar.status='on'
157-
x.Graph[1].Set[0].errorbar.color='purple'
158-
159-
x.plot(YY1,xs=X,G=0,S=0)
160-
x.plot(YY2,xs=X,G=0,S=1)
161-
x.plot(YY3,xs=X,G=1,S=0)
162-
# Now since we are passing lists and not numpy.mas we need to wrap them into a list
163-
x.plot([zero],xs=[[0.,2.*numpy.pi]],G=1,S=1)
154+
YY3 = numpy.ma.zeros((3, npoints), dtype='d')
155+
YY3[0] = Y3
156+
YY3[1] = Y3 * .1
157+
YY3[2] = Y3 * .1
158+
x.Graph[1].Set[0].type = 'xydxdy'
159+
x.Graph[1].Set[0].errorbar.status = 'on'
160+
x.Graph[1].Set[0].errorbar.color = 'purple'
161+
162+
x.plot(YY1, xs=X, G=0, S=0)
163+
x.plot(YY2, xs=X, G=0, S=1)
164+
x.plot(YY3, xs=X, G=1, S=0)
165+
# Now since we are passing lists and not numpy.mas we need to wrap them
166+
# into a list
167+
x.plot([zero], xs=[[0., 2. * numpy.pi]], G=1, S=1)
164168
# Finally let's save the result
165-
x.ps(TEMPDIR+'xmgrace_demo_Numeric') # postscript
166-
x.ps(TEMPDIR+'xmgrace_demo_Numeric_gray',color='grayscale') # grayscale postscript
167-
x.jpeg(TEMPDIR+'xmgrace_demo_Numeric',dpi=300,quality=80) # jpeg 300dpi, 80% quality compression
168-
x.pdf(TEMPDIR+'xmgrace_demo_Numeric')
169-
x.eps(TEMPDIR+'xmgrace_demo_Numeric')
170-
x.svg(TEMPDIR+'xmgrace_demo_Numeric')
171-
x.mif(TEMPDIR+'xmgrace_demo_Numeric')
172-
x.pnm(TEMPDIR+'xmgrace_demo_Numeric')
173-
x.png(TEMPDIR+'xmgrace_demo_Numeric')
174-
x.metafile(TEMPDIR+'xmgrace_demo_Numeric')
169+
x.ps(TEMPDIR + 'xmgrace_demo_Numeric') # postscript
170+
x.ps(TEMPDIR + 'xmgrace_demo_Numeric_gray',
171+
color='grayscale') # grayscale postscript
172+
# jpeg 300dpi, 80% quality compression
173+
x.jpeg(TEMPDIR + 'xmgrace_demo_Numeric', dpi=300, quality=80)
174+
x.pdf(TEMPDIR + 'xmgrace_demo_Numeric')
175+
x.eps(TEMPDIR + 'xmgrace_demo_Numeric')
176+
x.svg(TEMPDIR + 'xmgrace_demo_Numeric')
177+
x.mif(TEMPDIR + 'xmgrace_demo_Numeric')
178+
x.pnm(TEMPDIR + 'xmgrace_demo_Numeric')
179+
x.png(TEMPDIR + 'xmgrace_demo_Numeric')
180+
x.metafile(TEMPDIR + 'xmgrace_demo_Numeric')
175181

176182
# Finish
177183
x.close()

0 commit comments

Comments
 (0)