Add heatmap, lacks mapping between x-value and 2th
This commit is contained in:
parent
bdce18d195
commit
6e851b494b
1 changed files with 24 additions and 9 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import seaborn as sns
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,AutoMinorLocator)
|
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,AutoMinorLocator)
|
||||||
|
|
||||||
|
|
@ -20,7 +21,7 @@ def plot_diffractogram(data, options={}):
|
||||||
|
|
||||||
# Update options
|
# Update options
|
||||||
required_options = ['x_vals', 'y_vals', 'ylabel', 'xlabel', 'xunit', 'yunit', 'line', 'scatter', 'xlim', 'ylim', 'normalise', 'offset', 'offset_x', 'offset_y',
|
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', 'interactive_session_active']
|
'reflections_plot', 'reflections_indices', 'reflections_data', 'heatmap', 'cmap', 'plot_kind', 'palettes', 'interactive', 'rc_params', 'format_params', 'interactive_session_active']
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
'x_vals': '2th',
|
'x_vals': '2th',
|
||||||
|
|
@ -37,6 +38,8 @@ def plot_diffractogram(data, options={}):
|
||||||
'reflections_plot': False, # whether to plot reflections as a plot
|
'reflections_plot': False, # whether to plot reflections as a plot
|
||||||
'reflections_indices': False, # whether to plot the reflection indices
|
'reflections_indices': False, # whether to plot the reflection indices
|
||||||
'reflections_data': None, # Should be passed as a list of dictionaries on the form {path: rel_path, reflection_indices: number of indices, colour: [r,g,b], min_alpha: 0-1]
|
'reflections_data': None, # Should be passed as a list of dictionaries on the form {path: rel_path, reflection_indices: number of indices, colour: [r,g,b], min_alpha: 0-1]
|
||||||
|
'heatmap': False,
|
||||||
|
'cmap': 'viridis',
|
||||||
'plot_kind': None,
|
'plot_kind': None,
|
||||||
'palettes': [('qualitative', 'Dark2_8')],
|
'palettes': [('qualitative', 'Dark2_8')],
|
||||||
'interactive': False,
|
'interactive': False,
|
||||||
|
|
@ -70,12 +73,19 @@ def plot_diffractogram(data, options={}):
|
||||||
data['wavelength'][index] = wavelength
|
data['wavelength'][index] = wavelength
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if not isinstance(data['diffractogram'], list):
|
if not isinstance(data['diffractogram'], list):
|
||||||
data['diffractogram'] = [data['diffractogram']]
|
data['diffractogram'] = [data['diffractogram']]
|
||||||
data['wavelength'] = [data['wavelength']]
|
data['wavelength'] = [data['wavelength']]
|
||||||
|
|
||||||
|
if options['heatmap']:
|
||||||
|
data['heatmap'] = []
|
||||||
|
for diff in data['diffractogram']:
|
||||||
|
data['heatmap'].append(np.array(diff['I']))
|
||||||
|
|
||||||
|
data['heatmap'] = np.array(data['heatmap'])
|
||||||
|
data['heatmap'] = np.flipud(data['heatmap'])
|
||||||
|
|
||||||
# Sets the xlim if this has not bee specified
|
# Sets the xlim if this has not bee specified
|
||||||
if not options['xlim']:
|
if not options['xlim']:
|
||||||
options['xlim'] = [diffractogram[options['x_vals']].min(), diffractogram[options['x_vals']].max()]
|
options['xlim'] = [diffractogram[options['x_vals']].min(), diffractogram[options['x_vals']].max()]
|
||||||
|
|
@ -130,6 +140,11 @@ def plot_diffractogram(data, options={}):
|
||||||
colours = btp.generate_colours(['black'], kind='single')
|
colours = btp.generate_colours(['black'], kind='single')
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME Must be changed to map the x-value to the 2th-value somehow
|
||||||
|
if options['heatmap']:
|
||||||
|
sns.heatmap(data['heatmap'], cmap=options['cmap'])
|
||||||
|
|
||||||
|
else:
|
||||||
for diffractogram in data['diffractogram']:
|
for diffractogram in data['diffractogram']:
|
||||||
if options['line']:
|
if options['line']:
|
||||||
diffractogram.plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=next(colours), zorder=1)
|
diffractogram.plot(x=options['x_vals'], y=options['y_vals'], ax=ax, c=next(colours), zorder=1)
|
||||||
|
|
@ -168,7 +183,7 @@ def plot_diffractogram(data, options={}):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return diffractogram, fig, ax
|
return data['diffractogram'], fig, ax
|
||||||
|
|
||||||
|
|
||||||
def determine_grid_layout(options):
|
def determine_grid_layout(options):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue