Skip to content

Change objective and reference naming #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add options to change label names on plot
  • Loading branch information
Andrew Yang committed Jun 18, 2023
commit fb534efb95451147d9866ad77b0c336cde67b75b
12 changes: 6 additions & 6 deletions diffpy/pdfmorph/morphs/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ def checkConfig(self):
def plotInputs(self, xylabels=True):
'''Plot input arrays using matplotlib.pyplot

xylabels -- flag for updating x and y axis labels
xylabels -- flag for updating x and y axes labels

Return a list of matplotlib line objects.
'''
from matplotlib.pyplot import plot, xlabel, ylabel

rv = plot(self.x_target_in, self.y_target_in, label="***TARGET***")
rv = plot(self.x_morph_in, self.y_morph_in, label="***MORPH***")
rv = plot(self.x_target_in, self.y_target_in, label="target")
rv = plot(self.x_morph_in, self.y_morph_in, label="morph")
if xylabels:
xlabel(self.xinlabel)
ylabel(self.yinlabel)
Expand All @@ -179,7 +179,7 @@ def plotInputs(self, xylabels=True):
def plotOutputs(self, xylabels=True, **plotargs):
'''Plot output arrays using matplotlib.pyplot

xylabels -- flag for updating x and y axis labels
xylabels -- flag for updating x and y axes labels
plotargs -- arguments passed to the pylab plot function. Note that
"label" will be ignored.

Expand All @@ -189,8 +189,8 @@ def plotOutputs(self, xylabels=True, **plotargs):

pargs = dict(plotargs)
pargs.pop("label", None)
rv = plot(self.x_target_out, self.y_target_out, label="***TARGET***", **pargs)
rv = plot(self.x_morph_out, self.y_morph_out, label="***MORPH***", **pargs)
rv = plot(self.x_target_out, self.y_target_out, label="target", **pargs)
rv = plot(self.x_morph_out, self.y_morph_out, label="morph", **pargs)
if xylabels:
xlabel(self.xoutlabel)
ylabel(self.youtlabel)
Expand Down
4 changes: 2 additions & 2 deletions diffpy/pdfmorph/pdfmorph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def plot_morph(chain, ax=None, **kwargs):
fig, ax = plt.subplots()
rfit, grfit = chain.xy_morph_out
rdat, grdat = chain.xy_target_out
l_list = ax.plot(rfit, grfit, label='***MORPH***', **kwargs)
l_list += ax.plot(rdat, grdat, label='***TARGET***', **kwargs)
l_list = ax.plot(rfit, grfit, label='morph', **kwargs)
l_list += ax.plot(rdat, grdat, label='target', **kwargs)
ax.set_xlim([chain.config['rmin'], chain.config['rmax']])
ax.legend()
ax.set_xlabel(r'r ($\mathrm{\AA}$)')
Expand Down
27 changes: 26 additions & 1 deletion diffpy/pdfmorph/pdfmorphapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,24 @@ def custom_error(self, msg):
dest="plot",
help="Do not show the plot.",
)
group.add_option(
'--usefilenames',
action="store_true",
dest="usefilenames",
help="Use the file names as labels on plot."
)
group.add_option(
'--mlabel',
metavar="MLABEL",
dest="mlabel",
help="Set label for morphed data to MLABEL on plot. Ignored if using file names as labels.",
)
group.add_option(
'--tlabel',
metavar="TLABEL",
dest="tlabel",
help="Set label for target data to TLABEL on plot. Ignored if using file names as labels.",
)
Comment on lines +181 to +198
Copy link
Collaborator Author

@Sparks29032 Sparks29032 Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New option to set label names on plot (for fixing #46).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, see comment. Please put different issues on different PRs

group.add_option(
'--pmin', type="float", help="Minimum r-value to plot. Defaults to RMIN."
)
Expand Down Expand Up @@ -375,7 +393,14 @@ def main():

if opts.plot:
pairlist = [chain.xy_morph_out, chain.xy_target_out]
labels = ["***MORPH***", "***TARGET***"]
labels = ["morph", "target"] # Default label names
if opts.usefilenames:
labels = [pargs[0], pargs[1]]
else:
if opts.mlabel is not None:
labels[0] = opts.mlabel
if opts.tlabel is not None:
labels[1] = opts.tlabel
# Plot extent defaults to calculation extent
pmin = opts.pmin if opts.pmin is not None else opts.rmin
pmax = opts.pmax if opts.pmax is not None else opts.rmax
Expand Down