Skip to content

Commit f1d87ec

Browse files
authored
Merge pull request #14 from RomanMatthew/pyplot
Replace pylab with matplotlib.pyplot
2 parents d6e0cf3 + d4b8abc commit f1d87ec

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

diffpy/pdfmorph/pdfplot.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
##############################################################################
1515
"""Collection of plotting functions for PDFs."""
1616

17-
import pylab
17+
import matplotlib.pyplot as plt
1818
import numpy
1919

2020
# FIXME - make this return the figure object in the future, so several views
@@ -45,20 +45,19 @@ def plotPDFs(pairlist, labels=None, offset ='auto', rmin = None, rmax = None):
4545
labels = list(labels)
4646
labels.extend([""] * gap)
4747

48-
#pylab.clf()
49-
#pylab.ioff()
5048
for idx, pair in enumerate(pairlist):
5149
r, gr = pair
52-
pylab.plot(r, gr + idx * offset, label = labels[idx])
53-
pylab.xlim(rmin, rmax)
50+
plt.plot(r, gr + idx * offset, label = labels[idx])
51+
plt.xlim(rmin, rmax)
5452

5553
if gap == 0:
56-
pylab.legend(loc = 0)
54+
plt.legend(loc = 0)
5755

58-
pylab.xlabel("$r (\AA)$")
59-
pylab.ylabel("$G (\AA^{-1})$")
6056

61-
pylab.show()
57+
plt.xlabel("$r \mathrm{\AA}$")
58+
plt.ylabel("$G \mathrm{\AA}^{-1}$")
59+
60+
plt.show()
6261
return
6362

6463
def comparePDFs(pairlist, labels=None, rmin = None, rmax = None, show = True,
@@ -139,55 +138,54 @@ def comparePDFs(pairlist, labels=None, rmin = None, rmax = None, show = True,
139138
scale = min(1, max(scale, 0.8))
140139
figsize = [13.5, 4.5]
141140
figsize[0] *= scale
142-
fig = pylab.figure(1, figsize = figsize)
141+
fig = plt.figure(1, figsize = figsize)
143142
# Get the margins based on the figure size
144143
lm = 0.12 / scale
145144
bm = 0.20 / scale
146145
rm = 0.02 / scale
147146
tm = 0.15 / scale
148-
axes = pylab.Axes(fig, [lm, bm, 1 - lm - rm, 1 - bm - tm])
147+
axes = plt.Axes(fig, [lm, bm, 1 - lm - rm, 1 - bm - tm])
149148
fig.add_axes(axes)
150-
pylab.minorticks_on()
149+
plt.minorticks_on()
151150

152-
pylab.plot(rdat, grdat, label = labeldata, marker = 'o', markerfacecolor
151+
plt.plot(rdat, grdat, label = labeldata, marker = 'o', markerfacecolor
153152
= 'white', markeredgecolor = 'blue', markersize = 7,
154153
markeredgewidth = 0.75)
155-
pylab.plot(rfit, grfit, label = labelfit, linestyle = 'solid', linewidth =
154+
plt.plot(rfit, grfit, label = labelfit, linestyle = 'solid', linewidth =
156155
2, color = 'red')
157-
pylab.plot(rdat, offset*numpy.ones_like(diff), linestyle = '--', linewidth
156+
plt.plot(rdat, offset*numpy.ones_like(diff), linestyle = '--', linewidth
158157
= 1, color = 'black', dashes = (15, 15), aa = False)
159158
diff += offset
160-
pylab.plot(rdat, diff, label = labeldiff, linestyle = 'solid',
159+
plt.plot(rdat, diff, label = labeldiff, linestyle = 'solid',
161160
linewidth = 1.5, color = 'green')
162161

163162
if maglim is not None:
164163
# Add a line for the magnification cutoff
165-
pylab.axvline(maglim, 0, 1, linestyle = '--', color = 'black',
164+
plt.axvline(maglim, 0, 1, linestyle = '--', color = 'black',
166165
linewidth = 1.5, dashes = (14, 7))
167166
# FIXME - look for a place to put the maglim
168167
xpos = (rvmax*0.85 + maglim) / 2 / (rvmax - rvmin)
169168
if xpos <= 0.9:
170-
pylab.figtext(xpos, 0.7, "x%.1f"%mag, backgroundcolor='w')
169+
plt.figtext(xpos, 0.7, "x%.1f"%mag, backgroundcolor='w')
171170

172171
# Get a tight view
173-
pylab.xlim(rvmin, rvmax)
172+
plt.xlim(rvmin, rvmax)
174173
ymin = min(diff[sel])
175174
ymax = max(max(grdat[sel]), max(gtemp[sel]))
176175
yspan = ymax - ymin
177-
# Give a small boarder to the plot
176+
# Give a small border to the plot
178177
gap = 0.05 * yspan
179178
ymin -= gap
180179
ymax += gap
181-
pylab.ylim(ymin, ymax)
180+
plt.ylim(ymin, ymax)
182181

183182
# Make labels and legends
184-
pylab.xlabel("r $(\AA)$")
185-
pylab.ylabel("G $(\AA^{-1})$")
186-
#pylab.legend(loc = 0)
183+
plt.xlabel("r $\mathrm{\AA}$")
184+
plt.ylabel("G $(\mathrm{\AA}^{-1})$")
187185
if legend:
188-
pylab.legend(bbox_to_anchor=(0.005, 1.02, 0.99, .10), loc=3,
186+
plt.legend(bbox_to_anchor=(0.005, 1.02, 0.99, .10), loc=3,
189187
ncol=3, mode="expand", borderaxespad=0)
190-
if show: pylab.show()
188+
if show: plt.show()
191189

192190
return
193191

@@ -217,17 +215,17 @@ def truncatePDFs(r, gr, rmin = None, rmax = None):
217215

218216
def _configure():
219217
"""Configure look and feel."""
220-
import pylab
221-
pylab.rc("font", size = 40)
222-
pylab.rc("axes", linewidth = 2, labelsize = 30)
223-
pylab.rc("xtick", labelsize = 25)
224-
pylab.rc("xtick.major", size = 7)
225-
pylab.rc("xtick.minor", size = 3)
226-
pylab.rc("ytick", labelsize = 25)
227-
pylab.rc("ytick.major", size = 7)
228-
pylab.rc("ytick.minor", size = 3)
229-
pylab.rc("legend", fontsize = 18)
230-
pylab.rc("lines", markeredgewidth = 2) # thicker axes and symbols
218+
import matplotlib.pyplot as plt
219+
plt.rc("font", size = 40)
220+
plt.rc("axes", linewidth = 2, labelsize = 30)
221+
plt.rc("xtick", labelsize = 25)
222+
plt.rc("xtick.major", size = 7)
223+
plt.rc("xtick.minor", size = 3)
224+
plt.rc("ytick", labelsize = 25)
225+
plt.rc("ytick.major", size = 7)
226+
plt.rc("ytick.minor", size = 3)
227+
plt.rc("legend", fontsize = 18)
228+
plt.rc("lines", markeredgewidth = 2) # thicker axes and symbols
231229
return
232230

233231
def _findOffset(pairlist):

0 commit comments

Comments
 (0)