From f291454ccbec44aa5551f0aca2cc59836d132167 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Tue, 20 Oct 2015 10:40:49 -0400 Subject: [PATCH] palettes notebook --- examples/palettes.ipynb | 1371 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 1371 insertions(+) create mode 100644 examples/palettes.ipynb diff --git a/examples/palettes.ipynb b/examples/palettes.ipynb new file mode 100644 index 00000000..0e5dd2ce --- /dev/null +++ b/examples/palettes.ipynb @@ -0,0 +1,1371 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 81, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "old_pick_colors (generic function with 1 method)" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "using Plots; gadfly()\n", + "function old_pick_colors(grad,n)\n", + " grad=colorscheme(grad)\n", + " RGB[getColorZ(grad,z) for z in Plots.getpctrange(n)]\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "19-element Array{ColorTypes.RGB{FixedPointNumbers.UfixedBase{UInt8,8}},1}:\n", + " RGB{U8}(1.0,0.608,1.0) \n", + " RGB{U8}(0.0,1.0,1.0) \n", + " RGB{U8}(0.914,0.514,0.0) \n", + " RGB{U8}(0.0,0.522,1.0) \n", + " RGB{U8}(0.0,0.569,0.0) \n", + " RGB{U8}(0.914,0.0,0.412) \n", + " RGB{U8}(0.0,0.518,0.765) \n", + " RGB{U8}(0.976,1.0,0.055) \n", + " RGB{U8}(0.596,0.0,0.0) \n", + " RGB{U8}(0.953,0.988,1.0) \n", + " RGB{U8}(0.0,0.063,0.706) \n", + " RGB{U8}(0.306,0.188,0.0) \n", + " RGB{U8}(0.0,0.271,0.82) \n", + " RGB{U8}(0.718,0.576,0.584)\n", + " RGB{U8}(0.0,0.231,0.125) \n", + " RGB{U8}(0.0,0.867,1.0) \n", + " RGB{U8}(0.596,0.714,0.651)\n", + " RGB{U8}(0.38,0.0,0.0) \n", + " RGB{U8}(0.0,0.11,0.0) " + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# without specifying the background color, you get colors that are hard to see\n", + "cols = distinguishable_colors(20)[2:end]" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "19-element Array{ColorTypes.RGB{FixedPointNumbers.UfixedBase{UInt8,8}},1}:\n", + " RGB{U8}(0.38,0.0,0.027) \n", + " RGB{U8}(0.0,0.169,0.173) \n", + " RGB{U8}(0.569,0.231,0.0) \n", + " RGB{U8}(0.0,0.388,1.0) \n", + " RGB{U8}(0.0,0.569,0.0) \n", + " RGB{U8}(1.0,0.0,0.553) \n", + " RGB{U8}(0.0,0.675,0.925) \n", + " RGB{U8}(0.098,0.055,0.0) \n", + " RGB{U8}(1.0,0.478,0.0) \n", + " RGB{U8}(0.0,0.0,0.169) \n", + " RGB{U8}(0.808,0.639,1.0) \n", + " RGB{U8}(0.922,0.745,0.0) \n", + " RGB{U8}(0.0,0.816,1.0) \n", + " RGB{U8}(0.42,0.298,0.302)\n", + " RGB{U8}(0.0,1.0,0.816) \n", + " RGB{U8}(0.0,0.294,0.78) \n", + " RGB{U8}(0.18,0.286,0.235)\n", + " RGB{U8}(1.0,0.627,0.788) \n", + " RGB{U8}(0.722,1.0,0.294) " + ] + }, + "execution_count": 83, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# ugly, plus many similar, but at least you can see them\n", + "cols = distinguishable_colors(20,colorant\"white\")[2:end]" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "100-element Array{ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}},1}:\n", + " RGB{Float64}(0.0,0.0,0.9) \n", + " RGB{Float64}(0.0162408,0.0,0.879877)\n", + " RGB{Float64}(0.0324817,0.0,0.859754)\n", + " RGB{Float64}(0.0487225,0.0,0.839632)\n", + " RGB{Float64}(0.0649634,0.0,0.819509)\n", + " RGB{Float64}(0.0812042,0.0,0.799386)\n", + " RGB{Float64}(0.097445,0.0,0.779263) \n", + " RGB{Float64}(0.113686,0.0,0.75914) \n", + " RGB{Float64}(0.129927,0.0,0.739018) \n", + " RGB{Float64}(0.146168,0.0,0.718895) \n", + " RGB{Float64}(0.162408,0.0,0.698772) \n", + " RGB{Float64}(0.178649,0.0,0.678649) \n", + " RGB{Float64}(0.19489,0.0,0.658526) \n", + " ⋮ \n", + " RGB{Float64}(0.9,0.243137,0.0) \n", + " RGB{Float64}(0.9,0.221034,0.0) \n", + " RGB{Float64}(0.9,0.19893,0.0) \n", + " RGB{Float64}(0.9,0.176827,0.0) \n", + " RGB{Float64}(0.9,0.154724,0.0) \n", + " RGB{Float64}(0.9,0.13262,0.0) \n", + " RGB{Float64}(0.9,0.110517,0.0) \n", + " RGB{Float64}(0.9,0.0884135,0.0) \n", + " RGB{Float64}(0.9,0.0663102,0.0) \n", + " RGB{Float64}(0.9,0.0442068,0.0) \n", + " RGB{Float64}(0.9,0.0221034,0.0) \n", + " RGB{Float64}(0.9,0.0,0.0) " + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# this is the default gradient used as the base for color picking now\n", + "rainbow = colorscheme(:darkrainbow)\n", + "RGB[getColorZ(rainbow,z) for z in linspace(0,1,100)]" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "19-element Array{ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}},1}:\n", + " RGB{Float64}(0.0,0.0,0.9) \n", + " RGB{Float64}(0.9,0.0,0.0) \n", + " RGB{Float64}(0.0,0.401961,0.0) \n", + " RGB{Float64}(0.401961,0.0,0.401961) \n", + " RGB{Float64}(0.9,0.547059,0.0) \n", + " RGB{Float64}(0.20098,0.0,0.65098) \n", + " RGB{Float64}(0.20098,0.20098,0.20098) \n", + " RGB{Float64}(0.45,0.47451,0.0) \n", + " RGB{Float64}(0.9,0.273529,0.0) \n", + " RGB{Float64}(0.10049,0.0,0.77549) \n", + " RGB{Float64}(0.301471,0.0,0.526471) \n", + " RGB{Float64}(0.301471,0.10049,0.301471)\n", + " RGB{Float64}(0.10049,0.301471,0.10049) \n", + " RGB{Float64}(0.225,0.438235,0.0) \n", + " RGB{Float64}(0.675,0.510784,0.0) \n", + " RGB{Float64}(0.9,0.410294,0.0) \n", + " RGB{Float64}(0.9,0.136765,0.0) \n", + " RGB{Float64}(0.0502451,0.0,0.837745) \n", + " RGB{Float64}(0.150735,0.0,0.713235) " + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# better (IMO)... first 5 colors are good, then it gets worse\n", + "# this is the current default palette\n", + "old_pick_colors(:darkrainbow,19)" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "100-element Array{ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}},1}:\n", + " RGB{U8}(0.0,0.0,0.545) \n", + " RGB{Float64}(0.0338021,0.0,0.542193)\n", + " RGB{Float64}(0.0676041,0.0,0.539288)\n", + " RGB{Float64}(0.101406,0.0,0.536383) \n", + " RGB{Float64}(0.135208,0.0,0.533479) \n", + " RGB{Float64}(0.16901,0.0,0.530574) \n", + " RGB{Float64}(0.202812,0.0,0.527669) \n", + " RGB{Float64}(0.236615,0.0,0.524764) \n", + " RGB{Float64}(0.270417,0.0,0.521859) \n", + " RGB{Float64}(0.304219,0.0,0.518954) \n", + " RGB{Float64}(0.338021,0.0,0.516049) \n", + " RGB{Float64}(0.371823,0.0,0.513145) \n", + " RGB{Float64}(0.405625,0.0,0.51024) \n", + " ⋮ \n", + " RGB{Float64}(0.71358,0.239651,0.0) \n", + " RGB{Float64}(0.698264,0.217865,0.0) \n", + " RGB{Float64}(0.682947,0.196078,0.0) \n", + " RGB{Float64}(0.667631,0.174292,0.0) \n", + " RGB{Float64}(0.652314,0.152505,0.0) \n", + " RGB{Float64}(0.636997,0.130719,0.0) \n", + " RGB{Float64}(0.621681,0.108932,0.0) \n", + " RGB{Float64}(0.606364,0.087146,0.0) \n", + " RGB{Float64}(0.591048,0.0653595,0.0)\n", + " RGB{Float64}(0.575731,0.043573,0.0) \n", + " RGB{Float64}(0.560415,0.0217865,0.0)\n", + " RGB{Float64}(0.545098,0.0,0.0) " + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# what if we change the scaling of that gradient?\n", + "# see how we compressed the blues, and added darkened yellows\n", + "new_colorgradient = colorscheme([colorant\"darkblue\", colorant\"purple\", colorant\"darkgreen\", \n", + " Plots.darken(colorant\"yellow\",0.3), colorant\"orange\", colorant\"darkred\"], \n", + " [0, 0.15, 0.25, 0.4, 0.7, 1.0])\n", + "RGB[getColorZ(newgrad,z) for z in linspace(0,1,100)]" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "19-element Array{ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}},1}:\n", + " RGB{U8}(0.0,0.0,0.545) \n", + " RGB{Float64}(0.545098,0.0,0.0) \n", + " RGB{Float64}(0.8,0.682353,0.0) \n", + " RGB{Float64}(0.0,0.392157,0.0) \n", + " RGB{Float64}(0.924183,0.539216,0.0) \n", + " RGB{Float64}(0.418301,0.0,0.50915) \n", + " RGB{Float64}(0.583333,0.648693,0.0) \n", + " RGB{Float64}(0.925,0.660294,0.0) \n", + " RGB{Float64}(0.734641,0.269608,0.0) \n", + " RGB{Float64}(0.20915,0.0,0.527124) \n", + " RGB{Float64}(0.313725,0.147059,0.313725)\n", + " RGB{Float64}(0.291667,0.520425,0.0) \n", + " RGB{Float64}(0.7375,0.693382,0.0) \n", + " RGB{Float64}(0.8625,0.671324,0.0) \n", + " RGB{Float64}(0.9875,0.649265,0.0) \n", + " RGB{Float64}(0.829412,0.404412,0.0) \n", + " RGB{Float64}(0.639869,0.134804,0.0) \n", + " RGB{Float64}(0.104575,0.0,0.536111) \n", + " RGB{Float64}(0.313725,0.0,0.518137) " + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# the new gradient with the old color picker\n", + "old_pick_colors(newgrad, 19)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "new_pick_colors (generic function with 1 method)" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# a different method to choose from the gradient\n", + "function new_get_zvalues(n::Int)\n", + " #offsets = Plots.getpctrange(ceil(Int,n/4))\n", + " #offsets = linspace(0,0.25,ceil(Int,n/4)+1)[1:end-1]\n", + " offsets = Plots.getpctrange(ceil(Int,n/4)+1)/4\n", + " offsets = vcat(offsets[1], offsets[3:end])\n", + " @show offsets\n", + " zvalues = Float64[]\n", + " for offset in offsets\n", + " append!(zvalues, offset + [0.0, 0.5, 0.25, 0.75])\n", + " end\n", + " zvalues[1:n]\n", + "end\n", + "\n", + "# and a method to display the colors we will choose\n", + "function new_pick_colors(grad,n)\n", + " grad=colorscheme(grad)\n", + " RGB[getColorZ(grad,z) for z in new_get_zvalues(n)]\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "offsets = [0.0,0.125,0.0625,0.1875,0.03125]" + ] + }, + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "" + ], + "text/plain": [ + "19-element Array{ColorTypes.RGB{T<:Union{AbstractFloat,FixedPointNumbers.FixedPoint}},1}:\n", + " RGB{U8}(0.0,0.0,0.545) \n", + " RGB{Float64}(0.8,0.682353,0.0) \n", + " RGB{Float64}(0.0,0.392157,0.0) \n", + " RGB{Float64}(0.924183,0.539216,0.0) \n", + " RGB{Float64}(0.418301,0.0,0.50915) \n", + " RGB{Float64}(0.925,0.660294,0.0) \n", + " RGB{Float64}(0.583333,0.648693,0.0) \n", + " RGB{Float64}(0.734641,0.269608,0.0) \n", + " RGB{Float64}(0.20915,0.0,0.527124) \n", + " RGB{Float64}(0.8625,0.671324,0.0) \n", + " RGB{Float64}(0.291667,0.520425,0.0) \n", + " RGB{Float64}(0.829412,0.404412,0.0) \n", + " RGB{Float64}(0.313725,0.147059,0.313725)\n", + " RGB{Float64}(0.9875,0.649265,0.0) \n", + " RGB{Float64}(0.7375,0.693382,0.0) \n", + " RGB{Float64}(0.639869,0.134804,0.0) \n", + " RGB{Float64}(0.104575,0.0,0.536111) \n", + " RGB{Float64}(0.83125,0.676838,0.0) \n", + " RGB{Float64}(0.145833,0.456291,0.0) " + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "new_pick_colors(new_colorgradient, 19)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "plot(Plots.fakedata(100,10), l=(3, new_pick_colors(new_colorgradient, 19)))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 0.4.0-rc4", + "language": "julia", + "name": "julia-0.4" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "0.4.0" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}