Commit d46a9825 authored by Christian Schneider's avatar Christian Schneider
Browse files

Added matplotlib to data_table.plot_all() function. Set it as default

parent 5388718c
......@@ -288,7 +288,7 @@ class data_grid(data_module_base):
df = self.df[self.x_min:self.x_max, self.y_min:self.y_max]
df.plot.pcolormesh(self.name_x, self.name_y)
def imshow(self, colormap='magma', levels=256, zlabel_pos="right",
def imshow(self, colormap='magma', zlabel_pos="right",
labelpad=0, cbar_y=0.5, **kwargs):
"""Color plot using matplotlib
......@@ -314,9 +314,6 @@ class data_grid(data_module_base):
Position and orientation of zlabel next to colorbar. If location is
wrong, play with labelpad and cbar_y
"""
# Get colormap from matplotlib
#cmap = plt.cm.get_cmap(colormap, levels)
# Just get select range
df = self.df[self.x_min:self.x_max, self.y_min:self.y_max]
......
......@@ -12,12 +12,14 @@ from .plot_style import color_scheme, cc, check_color, color_labels
import holoviews as hv
import holoviews.operation.datashader as hd
import numpy as np
try:
import matplotlib.pyplot as plt
except NotImplementedError:
pass
# Plotting
import matplotlib
import matplotlib.pyplot as plt
import bokeh.plotting as bp
from bokeh.models import HoverTool
# Data analysis
import scipy.optimize as sp_opt
import scipy.signal as sp_sig
import scipy.interpolate as sp_intp
......@@ -460,27 +462,74 @@ class data_table(data_module_base):
elif engine in ['holoviews', 'h', 'hv']:
return self.plot_hv(color=color, **kwargs)
def plot_all(self, colormap=None):
"""Fast plot of the whole data in holoviews"""
def plot_all(self, engine='p', colormap=None, legend=True, **kwargs):
"""Plot all columns
# Get default colormap
if colormap is None:
colormap = color_scheme
Parameters
------------
engine : 'p', 'h'
Plot engine. Currently implemented are pyplot and holoviews
colormap : None, 'magma', 'viridis', ['#123456', '#aabbcc']
Colormap for plotting. None will pick a default colormap.
You can specify names of default palettes 'magma', 'viridis', etc
or give an own array of hex colors.
legend : bool
Plot legend
**kwargs
Additional keywords for matplotlib. Like linestyle='-', etc...
"""
# Get number of plots
n_plots = len(self.df.keys()) - 1
# Get colormap
if isinstance(colormap, str):
# Get colormap from default library by name
tmp = plt.cm.get_cmap(colormap, n_plots)
colormap = [matplotlib.colors.rgb2hex(tmp(i)) for
i in range(n_plots)]
elif colormap is None:
# Use 8 default colors if less than 8 columns to plot
if n_plots <= len(color_scheme):
colormap = color_scheme
# Use more colors
else:
tmp = plt.cm.get_cmap('magma', n_plots)
colormap = [matplotlib.colors.rgb2hex(tmp(i)) for
i in range(n_plots)]
# Get columns
cols = self.df.columns[1:]
# Create dots of the first point for legend (bug in holoviews)
color_points = hv.NdOverlay({cols[i]:
hv.Points([[self.x[0],
self.df[cols[i]][0]]],
label=str(cols[i]))
.opts(style=dict(color=colormap[i]))
for i in range(len(cols))})
plot = color_points
for col, c in zip(cols, colormap):
plot *= self.plot_hv(y=col, color=c)
return plot
# Holoviews
if engine[0].lower() == 'h':
# Create dots of the first point for legend (bug in holoviews)
color_points = hv.NdOverlay({cols[i]:
hv.Points([[self.x[0],
self.df[cols[i]][0]]],
label=str(cols[i]))
.opts(style=dict(color=colormap[i]))
for i in range(len(cols))})
plot = color_points
for col, c in zip(cols, colormap):
plot *= self.plot_hv(y=col, color=c)
return plot
# Matplotlib
else:
for i in range(1, len(self.df.keys())):
plt.plot(self.x, self.df[self.df.keys()[i]],
label=self.df.keys()[i],
color=colormap[i-1],
**kwargs)
plt.grid(True)
if legend:
plt.legend(bbox_to_anchor=(1.04,0.5),
loc="center left",
ncol=4,
borderaxespad=0)
plt.show()
def fit(self, fitfunc, fit_p_init, boundaries = None,plot=True,
plot_init=False, plot_params=True, labels=None, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment