<commit_before>'''
Plot up stuff with colormaps:
colormap gallery
lightness
sample MCH data with each colormap.
'''

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import cmtamu
from skimage import color
import test

mpl.rcParams.update({'font.size': 14})
mpl.rcParams['font.sans-serif'] = 'Arev Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif'
mpl.rcParams['mathtext.fontset'] = 'custom'
mpl.rcParams['mathtext.cal'] = 'cursive'
mpl.rcParams['mathtext.rm'] = 'sans'
mpl.rcParams['mathtext.tt'] = 'monospace'
mpl.rcParams['mathtext.it'] = 'sans:italic'
mpl.rcParams['mathtext.bf'] = 'sans:bold'
mpl.rcParams['mathtext.sf'] = 'sans'
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'

# list of colormaps for several functions
cmaps = [cmtamu.salinity, cmtamu.temp, cmtamu.o2, cmtamu.chl, cmtamu.cdom, cmtamu.turb]

def plot_lightness():
    '''
    Plot lightness of colormaps together.
    '''

    dc = 1.
    x = np.linspace(0.0, 1.0, 256)
    locs = [] # locations for text labels

    fig = plt.figure(figsize=(16,6))
    ax = fig.add_subplot(111)
    ax.set_xlim(-0.1, 6.1)
    ax.set_ylim(0, 100)
    ax.set_xlabel('Lightness for each colormap')

    for j, cmap in enumerate(cmaps):
        rgb = cmap(x)[np.newaxis,:,:3]
        lab = color.rgb2lab(rgb)
        L = lab[0,:,0]
        if L[-1] > L[0]:
            ax.scatter(x+j*dc, L, c=x, cmap=cmap, s=300, linewidths=0.)
        else:
            ax.scatter(x+j*dc, L[::-1], c=x, cmap=cmap, s=300, linewidths=0.)
        locs.append(x[-1]+j*dc) # store locations for colormap labels

    # Set up labels for colormaps
    ax.xaxis.set_ticks_position('top')
    ticker = mpl.ticker.FixedLocator(locs)
    ax.xaxis.set_major_locator(ticker)
    formatter = mpl.ticker.FixedFormatter([cmap.name for cmap in cmaps])
    ax.xaxis.set_major_formatter(formatter)
    labels = ax.get_xticklabels()
    for label in labels:
        label.set_rotation(60)

    fig.savefig('../figures/lightness.png', bbox_inches='tight')


def print_colormaps():
    '''
    Print colormaps in 256 RGB colors to text files.
    '''

    for cmap in cmaps:

        np.savetxt(cmap.name + '-rgb.txt', cmap(np.linspace(0,1,256))[np.newaxis,:,:3][0])


def plot_data():<commit_msg>fixed so colormaps are in correct lightness order<commit_after>'''
Plot up stuff with colormaps:
colormap gallery
lightness
sample MCH data with each colormap.
'''

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import cmtamu
from skimage import color
import test

mpl.rcParams.update({'font.size': 14})
mpl.rcParams['font.sans-serif'] = 'Arev Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif'
mpl.rcParams['mathtext.fontset'] = 'custom'
mpl.rcParams['mathtext.cal'] = 'cursive'
mpl.rcParams['mathtext.rm'] = 'sans'
mpl.rcParams['mathtext.tt'] = 'monospace'
mpl.rcParams['mathtext.it'] = 'sans:italic'
mpl.rcParams['mathtext.bf'] = 'sans:bold'
mpl.rcParams['mathtext.sf'] = 'sans'
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'

# list of colormaps for several functions
cmaps = [cmtamu.salinity, cmtamu.temp, cmtamu.o2, cmtamu.chl, cmtamu.cdom, cmtamu.turb]

def plot_lightness():
    '''
    Plot lightness of colormaps together.
    '''

    dc = 1.
    x = np.linspace(0.0, 1.0, 256)
    locs = [] # locations for text labels

    fig = plt.figure(figsize=(16,6))
    ax = fig.add_subplot(111)
    ax.set_xlim(-0.1, 6.1)
    ax.set_ylim(0, 100)
    ax.set_xlabel('Lightness for each colormap')

    for j, cmap in enumerate(cmaps):
        rgb = cmap(x)[np.newaxis,:,:3]
        lab = color.rgb2lab(rgb)
        L = lab[0,:,0]
        if L[-1] > L[0]:
            ax.scatter(x+j*dc, L, c=x, cmap=cmap, s=300, linewidths=0.)
        else:
            ax.scatter(x+j*dc, L[::-1], c=x[::-1], cmap=cmap, s=300, linewidths=0.)
        locs.append(x[-1]+j*dc) # store locations for colormap labels

    # Set up labels for colormaps
    ax.xaxis.set_ticks_position('top')
    ticker = mpl.ticker.FixedLocator(locs)
    ax.xaxis.set_major_locator(ticker)
    formatter = mpl.ticker.FixedFormatter([cmap.name for cmap in cmaps])
    ax.xaxis.set_major_formatter(formatter)
    labels = ax.get_xticklabels()
    for label in labels:
        label.set_rotation(60)

    fig.savefig('figures/lightness.png', bbox_inches='tight')


def print_colormaps():
    '''
    Print colormaps in 256 RGB colors to text files.
    '''

    for cmap in cmaps:

        np.savetxt(cmap.name + '-rgb.txt', cmap(np.linspace(0,1,256))[np.newaxis,:,:3][0])


def plot_data():
{'fraction_non_alphanumeric': 0.15085368489301923, 'fraction_numerical': 0.02312513507672358, 'mean_word_length': 3.5641025641025643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7171147', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1819, 'n_words': 384}