From 223be18c3e451b8be2a962bba126f44c9eab41db Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Wed, 30 Mar 2022 17:40:06 +0200 Subject: [PATCH] Change default behaviour with 10+ plots --- beamtime/plotting.py | 20 ++++++++++++-------- beamtime/xrd/io.py | 6 ++---- beamtime/xrd/plot.py | 13 ++++++++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/beamtime/plotting.py b/beamtime/plotting.py index dd9a481..4e058ac 100644 --- a/beamtime/plotting.py +++ b/beamtime/plotting.py @@ -377,16 +377,20 @@ def update_rc_params(rc_params): plt.rcParams.update({key: rc_params[key]}) -def generate_colours(palettes): +def generate_colours(palettes, kind=None): - # Creates a list of all the colours that is passed in the colour_cycles argument. Then makes cyclic iterables of these. - colour_collection = [] - for palette in palettes: - mod = importlib.import_module("palettable.colorbrewer.%s" % palette[0]) - colour = getattr(mod, palette[1]).mpl_colors - colour_collection = colour_collection + colour + if kind == 'single': + colour_cycle = itertools.cycle(palettes) - colour_cycle = itertools.cycle(colour_collection) + else: + # Creates a list of all the colours that is passed in the colour_cycles argument. Then makes cyclic iterables of these. + colour_collection = [] + for palette in palettes: + mod = importlib.import_module("palettable.colorbrewer.%s" % palette[0]) + colour = getattr(mod, palette[1]).mpl_colors + colour_collection = colour_collection + colour + + colour_cycle = itertools.cycle(colour_collection) return colour_cycle \ No newline at end of file diff --git a/beamtime/xrd/io.py b/beamtime/xrd/io.py index 5aa2fb1..14c0f98 100644 --- a/beamtime/xrd/io.py +++ b/beamtime/xrd/io.py @@ -252,7 +252,7 @@ def read_brml(data, options={}, index=0): start = float(chain.findall('ScanInformation/ScaleAxes/ScaleAxisInfo/Start')[0].text) stop = float(chain.findall('ScanInformation/ScaleAxes/ScaleAxisInfo/Stop')[0].text) - increment = float(chain.findall('ScanInformation/ScaleAxes/ScaleAxisInfo/Increment')[0].text) + @@ -262,7 +262,7 @@ def read_brml(data, options={}, index=0): intensity = [] for r in raw: - if r > 600: + if r > 601: intensity.append(r) intensity = np.array(intensity) @@ -478,9 +478,7 @@ def translate_wavelengths(data, wavelength, to_wavelength=None): def find_wavelength_from_xy(path): - print(path) - wavelength_dict = {'Cu': 1.54059, 'Mo': 0.71073} with open(path, 'r') as f: diff --git a/beamtime/xrd/plot.py b/beamtime/xrd/plot.py index 770b5a8..1a9429c 100644 --- a/beamtime/xrd/plot.py +++ b/beamtime/xrd/plot.py @@ -20,7 +20,7 @@ def plot_diffractogram(data, options={}): # Update options required_options = ['x_vals', 'y_vals', 'ylabel', 'xlabel', 'xunit', 'yunit', 'line', 'scatter', 'xlim', 'ylim', 'normalise', 'offset', 'offset_x', 'offset_y', - 'reflections_plot', 'reflections_indices', 'reflections_data', 'plot_kind', 'palettes', 'interactive', 'rc_params', 'format_params'] + 'reflections_plot', 'reflections_indices', 'reflections_data', 'plot_kind', 'palettes', 'interactive', 'rc_params', 'format_params', 'interactive_session_active'] default_options = { 'x_vals': '2th', @@ -45,6 +45,10 @@ def plot_diffractogram(data, options={}): 'format_params': {}, } + if 'offset_y' not in options.keys(): + if len(data['path']) > 10: + default_options['offset_y'] = 0.05 + options = aux.update_options(options=options, required_options=required_options, default_options=default_options) # Convert data['path'] to list to allow iteration over this to accommodate both single and multiple diffractograms @@ -62,6 +66,7 @@ def plot_diffractogram(data, options={}): for index in range(len(data['path'])): diffractogram, wavelength = xrd.io.read_data(data=data, options=options, index=index) + data['diffractogram'][index] = diffractogram data['wavelength'][index] = wavelength @@ -113,7 +118,10 @@ def plot_diffractogram(data, options={}): ax = ax[-1] - colours = btp.generate_colours(options['palettes']) + if len(data['path']) < 10: + colours = btp.generate_colours(options['palettes']) + else: + colours = btp.generate_colours(['black'], kind='single') for diffractogram in data['diffractogram']: @@ -183,7 +191,6 @@ def plot_diffractogram_interactive(data, options): if not ymax or (ymax < (diffractogram['I'].max())):#+index*options['offset_y'])): ymax = diffractogram['I'].max()#+index*options['offset_y'] - print(ymax) ymin_start = ymin - 0.1*ymax