[density] rewritten for consistent coloring

This commit is contained in:
mzwiessele 2015-10-03 22:23:43 +01:00
parent d7b5f45b71
commit 2d38c22345
2 changed files with 34 additions and 13 deletions

View file

@ -27,6 +27,11 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#===============================================================================
from matplotlib.colors import LinearSegmentedColormap
from matplotlib import cm
from . import Tango
'''
This file is for defaults for the gpy plot, specific to the plotting library.
@ -38,9 +43,6 @@ In the code, always ise plotting.gpy_plots.defaults to get the defaults, as
it gives back an empty default, when defaults are not defined.
'''
from matplotlib import cm
from . import Tango
# Data:
data_1d = dict(lw=1.5, marker='x', edgecolor='k')
data_2d = dict(s=35, edgecolors='none', linewidth=0., cmap=cm.get_cmap('hot'), alpha=.5)
@ -53,5 +55,5 @@ yerrorbar = dict(ecolor=Tango.colorsHex['darkRed'], fmt='none', elinewidth=.5, a
meanplot_1d = dict(color=Tango.colorsHex['mediumBlue'], linewidth=2)
meanplot_2d = dict(cmap='hot', linewidth=.5)
samples_1d = dict(color=Tango.colorsHex['mediumBlue'], linewidth=.3)
confidence_interval = dict(edgecolor=Tango.colorsHex['darkBlue'],linewidth=.5,facecolor=Tango.colorsHex['lightBlue'],alpha=.3)
density = dict(facecolor=Tango.colorsHex['mediumBlue'],edgecolors='none')
confidence_interval = dict(edgecolor=Tango.colorsHex['darkBlue'],linewidth=.5,facecolor=Tango.colorsHex['lightBlue'],alpha=.2)
density = dict(alpha=.5, facecolor=Tango.colorsHex['mediumBlue'], edgecolors='none')

View file

@ -31,6 +31,7 @@ import numpy as np
from matplotlib import pyplot as plt
from ..abstract_plotting_library import AbstractPlottingLibrary
from . import defaults
from matplotlib.colors import LinearSegmentedColormap
class MatplotlibPlots(AbstractPlottingLibrary):
def __init__(self):
@ -99,19 +100,37 @@ class MatplotlibPlots(AbstractPlottingLibrary):
def fill_gradient(self, canvas, X, percentiles, **kwargs):
ax = canvas
plots = []
if not 'alpha' in kwargs.keys():
kwargs['alpha'] = 3./max(4, (len(percentiles)))
if 'facecolors' in kwargs:
kwargs['facecolor'] = kwargs.pop('facecolors')
if 'cmap' not in kwargs:
kwargs['cmap'] = LinearSegmentedColormap.from_list('WhToColor', ((1., 1., 1.), kwargs['facecolor']), N=len(percentiles)-1)
kwargs['cmap']._init()
if 'alpha' in kwargs:
kwargs['cmap']._lut[:, -1] = kwargs['alpha']
if 'array' not in kwargs:
if (len(percentiles)%2) == 0:
up = np.linspace(0, 1, len(percentiles)/2)
kwargs['array'] = np.r_[up, up[::-1][1:]]
else:
up = np.linspace(0, 1, len(percentiles)/2)
kwargs['array'] = np.r_[up, up[::-1]]
# pop where from kwargs
where = kwargs.pop('where') if 'where' in kwargs else None
# pop interpolate, which we actually do not do here!
if 'interpolate' in kwargs: kwargs.pop('interpolate')
def pairwise(inlist):
l = len(inlist)
for i in range(int(np.ceil(l/2.))):
yield inlist[:][i], inlist[:][(l-1)-i]
from itertools import tee, izip
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return izip(a, b)
polycol = []
for y1, y2 in pairwise(percentiles):
import matplotlib.mlab as mlab