Skip to content

Commit fb534ef

Browse files
author
Andrew Yang
committed
Add options to change label names on plot
1 parent ed89286 commit fb534ef

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

diffpy/pdfmorph/morphs/morph.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ def checkConfig(self):
163163
def plotInputs(self, xylabels=True):
164164
'''Plot input arrays using matplotlib.pyplot
165165
166-
xylabels -- flag for updating x and y axis labels
166+
xylabels -- flag for updating x and y axes labels
167167
168168
Return a list of matplotlib line objects.
169169
'''
170170
from matplotlib.pyplot import plot, xlabel, ylabel
171171

172-
rv = plot(self.x_target_in, self.y_target_in, label="***TARGET***")
173-
rv = plot(self.x_morph_in, self.y_morph_in, label="***MORPH***")
172+
rv = plot(self.x_target_in, self.y_target_in, label="target")
173+
rv = plot(self.x_morph_in, self.y_morph_in, label="morph")
174174
if xylabels:
175175
xlabel(self.xinlabel)
176176
ylabel(self.yinlabel)
@@ -179,7 +179,7 @@ def plotInputs(self, xylabels=True):
179179
def plotOutputs(self, xylabels=True, **plotargs):
180180
'''Plot output arrays using matplotlib.pyplot
181181
182-
xylabels -- flag for updating x and y axis labels
182+
xylabels -- flag for updating x and y axes labels
183183
plotargs -- arguments passed to the pylab plot function. Note that
184184
"label" will be ignored.
185185
@@ -189,8 +189,8 @@ def plotOutputs(self, xylabels=True, **plotargs):
189189

190190
pargs = dict(plotargs)
191191
pargs.pop("label", None)
192-
rv = plot(self.x_target_out, self.y_target_out, label="***TARGET***", **pargs)
193-
rv = plot(self.x_morph_out, self.y_morph_out, label="***MORPH***", **pargs)
192+
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
193+
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
194194
if xylabels:
195195
xlabel(self.xoutlabel)
196196
ylabel(self.youtlabel)

diffpy/pdfmorph/pdfmorph_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ def plot_morph(chain, ax=None, **kwargs):
268268
fig, ax = plt.subplots()
269269
rfit, grfit = chain.xy_morph_out
270270
rdat, grdat = chain.xy_target_out
271-
l_list = ax.plot(rfit, grfit, label='***MORPH***', **kwargs)
272-
l_list += ax.plot(rdat, grdat, label='***TARGET***', **kwargs)
271+
l_list = ax.plot(rfit, grfit, label='morph', **kwargs)
272+
l_list += ax.plot(rdat, grdat, label='target', **kwargs)
273273
ax.set_xlim([chain.config['rmin'], chain.config['rmax']])
274274
ax.legend()
275275
ax.set_xlabel(r'r ($\mathrm{\AA}$)')

diffpy/pdfmorph/pdfmorphapp.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ def custom_error(self, msg):
178178
dest="plot",
179179
help="Do not show the plot.",
180180
)
181+
group.add_option(
182+
'--usefilenames',
183+
action="store_true",
184+
dest="usefilenames",
185+
help="Use the file names as labels on plot."
186+
)
187+
group.add_option(
188+
'--mlabel',
189+
metavar="MLABEL",
190+
dest="mlabel",
191+
help="Set label for morphed data to MLABEL on plot. Ignored if using file names as labels.",
192+
)
193+
group.add_option(
194+
'--tlabel',
195+
metavar="TLABEL",
196+
dest="tlabel",
197+
help="Set label for target data to TLABEL on plot. Ignored if using file names as labels.",
198+
)
181199
group.add_option(
182200
'--pmin', type="float", help="Minimum r-value to plot. Defaults to RMIN."
183201
)
@@ -375,7 +393,14 @@ def main():
375393

376394
if opts.plot:
377395
pairlist = [chain.xy_morph_out, chain.xy_target_out]
378-
labels = ["***MORPH***", "***TARGET***"]
396+
labels = ["morph", "target"] # Default label names
397+
if opts.usefilenames:
398+
labels = [pargs[0], pargs[1]]
399+
else:
400+
if opts.mlabel is not None:
401+
labels[0] = opts.mlabel
402+
if opts.tlabel is not None:
403+
labels[1] = opts.tlabel
379404
# Plot extent defaults to calculation extent
380405
pmin = opts.pmin if opts.pmin is not None else opts.rmin
381406
pmax = opts.pmax if opts.pmax is not None else opts.rmax

0 commit comments

Comments
 (0)