Example #1
0
	def colmap(df,var,idvar,colormap,start_col=.2):
	    '''Function reads in a variable and determines the colors corresponding to each
	    float value in the distribution.  It returns a dict mapping the color to each
	    corresponding idvar.'''

	    #Define min and max parameter values
	    minval=df[var].min()
	    maxval=df[var].max()
	    
	    #Generate color mapper
	    colmap=color.color_mapper((minval,maxval),cmap=colormap,start=start_col)
	    
	    #Generate containers for id values and colors
	    id_list=[]
	    col_list=[]
	    
	    #For each feature...
	    for idval in df[idvar]:
	        #...throw idval in the list...
	        id_list.append(idval)
	        #...and the corresponding color in the other list
	        col_list.append(colmap(df[df[idvar]==idval][var]))
	    
	    #Create mapping between idval and colors
	    col_dict=dict(zip(id_list,col_list))
	    return col_dict
def plot_all_free_energies():
    temps = [500, 600, 700, 800]

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    colors = ['']
    map_color = color.color_mapper([500, 800], cmap='copper')
    for T in temps:
        fname = "data/pseudo_binary_free/adaptive_bias{}K_-650mev.h5".format(T)
        with h5.File(fname, 'r') as infile:
            x = np.array(infile["x"]) / 2000.0
            G = -np.array(infile["bias"])

        res = linregress(x, G)
        slope = res[0]
        interscept = res[1]
        G -= (slope * x + interscept)
        G -= G[0]
        ax.plot(x, G, drawstyle='steps', color=map_color(T))
    ax.set_ylabel("\$\\beta \Delta G\$")
    ax.set_xlabel("MgSi concentration")
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    plt.show()
Suppose you want to plot a series of curves, and each curve describes
a response to different values of a parameter. ``color_mapper`` returns
a function that maps a parameter value to an RGBA color in a color map.

"""
import numpy as np
import matplotlib.pyplot as plt

from mpltools import layout
from mpltools import color


pvalues = np.logspace(-1, 0, 4)
parameter_range = (pvalues[0], pvalues[-1])
# Pass parameter range so that color mapper knows how to normalize the data.
map_color1 = color.color_mapper(parameter_range)
map_color2 = color.color_mapper(parameter_range, cmap='BuPu', start=0.2)

figsize = layout.figaspect(aspect_ratio=0.5)
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=figsize)
x = np.linspace(0, 10)
for pval in pvalues:
    y = np.sin(x) * np.exp(-pval * x)
    ax1.plot(x, y, 's', color=map_color1(pval))
    ax2.plot(x, y, lw=3, color=map_color2(pval))

for ax in (ax1, ax2):
    leg = ax.legend(['%0.1f' % v for v in pvalues], loc='lower right', ncol=2)
    leg.set_title('decay rate')
    ax.set_ylim(-1.5, 1)
Example #4
0
import sys, getopt
import numpy as np
import pandas as pd
import matplotlib as mp
from sets import Set
from matplotlib import pyplot as plt
from mpltools import color

mp.rcParams['axes.linewidth'] = 0.05

mycolor1 = color.color_mapper((0, 5), cmap='Oranges')
mycolor2 = color.color_mapper((0, 5), cmap='Blues')
mycolor3 = color.color_mapper((0, 5), cmap='Greens')
mycolor4 = color.color_mapper((0, 5), cmap='pink')

## colors
myblue = '#3355A9'
mylblue = '#7799ff'
myred = '#ac2318'
mylred = '#ff675c'
myyellow = '#d2a41a'
mygreen = '#8fdf9d'
mylgreen = '#8fdf9d'
mygray = '#999999'

usage = 'view_matrix_new.py -i <inputfile> -t <mm|sparse|adj|hyper|patoh> [-s <size>] [-p <partitionfile>] [-v]'


def parse_arguments(argv):
    try:
        opts, args = getopt.getopt(argv, "hi:t:s:p:v")
Suppose you want to plot a series of curves, and each curve describes
a response to different values of a parameter. ``color_mapper`` returns
a function that maps a parameter value to an RGBA color in a color map.

"""
import numpy as np
import matplotlib.pyplot as plt

from mpltools import layout
from mpltools import color

pvalues = np.logspace(-1, 0, 4)
parameter_range = (pvalues[0], pvalues[-1])
# Pass parameter range so that color mapper knows how to normalize the data.
map_color1 = color.color_mapper(parameter_range)
map_color2 = color.color_mapper(parameter_range, cmap='BuPu', start=0.2)

figsize = layout.figaspect(aspect_ratio=0.5)
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=figsize)
x = np.linspace(0, 10)
for pval in pvalues:
    y = np.sin(x) * np.exp(-pval * x)
    ax1.plot(x, y, 's', color=map_color1(pval))
    ax2.plot(x, y, lw=3, color=map_color2(pval))

for ax in (ax1, ax2):
    leg = ax.legend(['%0.1f' % v for v in pvalues], loc='lower right', ncol=2)
    leg.set_title('decay rate')
    ax.set_ylim(-1.5, 1)
Example #6
0
#!/usr/bin/python
from matplotlib import pyplot as p
import scipy as sp
import numpy as np
import sys
import csv
import glob
from sets import Set
from mpltools import color
from mpltools import layout
import os

global colors,pvalues
pvalues = np.logspace(-1,0,6)
parameter_range = (pvalues[0],pvalues[-1])
colors = color.color_mapper(parameter_range,cmap='BuPu',start=0.2)
colors2 = color.color_mapper(parameter_range,cmap='PuOr',start=0.2)


def autolabel_float(ax,rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.07*height, '%1.1f'%float(height),
                ha='center', va='bottom')


def autolabel(ax,rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
fig1 = plt.figure(figsize=(w,h))
ax1 = fig1.add_subplot(121)
ax2 = fig1.add_subplot(122)

list_ax = [ax1,ax2]

ms  = 10 # marker size
mew = 2  # marker edge width
lw  = 3



list_kernel_delta_wdith = [0.05,0.100,0.150,0.200,0.300,0.400]

range = [list_kernel_delta_wdith[0], list_kernel_delta_wdith[-1]] 
map_color = color.color_mapper(range, cmap='rainbow', start=0.0)

normalization = 0.5/D_cutoff*density
for delta in list_kernel_delta_wdith:

    re_Sigma = get_KR(list_xi,delta)*normalization
    im_Sigma =-get_KI(list_xi,delta)*normalization

    c=map_color(delta)

    ax1.plot(list_xi/D_cutoff,-im_Sigma,'-',c=c,alpha=1.0,lw=lw,label='$\Gamma_\gamma= %i$ meV'%(1000*delta))
    ax2.plot(list_xi/D_cutoff,re_Sigma,'-',c=c,alpha=1.0,lw=lw,label='__nolabel__')
#I0 = 10. # eV a0^2
#for I0 in [1.,10.,50.]:
#    re_Sigma_I0 = I0*normalization
#    ax2.plot(list_xi/D_cutoff,re_Sigma_I0*N.ones_like(list_xi),'--',alpha=1.0,lw=lw,label='$I_0= %4.1f$ eV $a_0^2$'%(I0))