Leandro Acquaroli
Leandro Acquaroli

Reputation: 65

How to use a colormap from pyplot.jl as a function in julia-lang

What would be the way to get in Julia-lang, something similar to

import numpy as np
import matplotlib.pyplot as plt
i = 0, f = 255, N = 100
colors = [ plt.cm.viridis(x) for x in np.linspace(i, f, N) ]

in Python? Generally speaking, I am looking for a way to get the RGB list from a colormap using Pyplot.jl in Julia-lang with a desired number of colors (N).

Upvotes: 2

Views: 663

Answers (1)

Tom Breloff
Tom Breloff

Reputation: 1802

This is easiest using PlotUtils (which is re-exported on using Plots):

julia> using PlotUtils

julia> cm = cgrad(:viridis);

julia> colors = [cm[i] for i in linspace(0,1,10)]
10-element Array{ColorTypes.RGBA{Float64},1}:
 RGBA{Float64}(0.267004,0.004874,0.329415,1.0)
 RGBA{Float64}(0.280935,0.155726,0.468508,1.0)
 RGBA{Float64}(0.242949,0.291862,0.537908,1.0)
 RGBA{Float64}(0.190784,0.406937,0.555933,1.0)
 RGBA{Float64}(0.147463,0.512137,0.556955,1.0)
 RGBA{Float64}(0.120243,0.618071,0.536316,1.0)
 RGBA{Float64}(0.209417,0.718547,0.472197,1.0)
 RGBA{Float64}(0.422721,0.805438,0.351155,1.0)
 RGBA{Float64}(0.710003,0.8685,0.169494,1.0)  
 RGBA{Float64}(0.993248,0.906157,0.143936,1.0)

Upvotes: 3

Related Questions