I am using cmocean color bar and I like to plot the color bar in reverse direction means upside down. I tried a lot using Matlab also to flip it upside down but unsuccessful and too much of time-consuming. So is it possible to invert the colour the cmocean color bar like blue_orange to orange_blue?
#!/usr/bin/ruby
#-- return the next non-comment, non-blank line.
def next_line(f)
line = nil
while (line = f.gets) && (line =
end
return line
end
#-- Main loop over palette files ---
ARGV.each {|fname|
inf = File.open(fname,"r")
line = next_line(inf) #-- first non-comment line
begin
if ! line then raise "#{fname}: empty? Skipping. . ." end
case line
when /\s*(rgb_mapping\s+by_value)/i, /\s*(rgb_mapping\s+by_level)/i
raise "#{fname}: cannot invert #{$1} ."
end
rescue RuntimeError => err
$stderr.puts err
inf.close
next
end
ofname = "inverse-" + File.basename(fname)
ouf = File.open(ofname, "w")
if line =
ouf.puts line
line = next_line(inf)
end
buff = Array.new
while line
v, *rest = line.split
buff << "#{100 - v.to_f} #{rest.join(' ')}"
line = next_line(inf)
end
inf.close
buff.reverse_each {|e| ouf.puts e }
ouf.close
}