2

I want to make a rainbow filled box on the visible light area with planck distribution curve. I don't have any idea how to fill this box with rainbow...

I set a box like

set object 1 rectangle from 3600,0 to 8200,3.6 fs solid 0.4

and

fc rgb 

is for coloring. But only what I can do is fill it with one color.

I saw some coloring demos for plotting, like with pm3d or some palette, but it doesn't put em onto obj coloring with palette.

it's from wiki and I want that rainbow box: enter image description here

E. Moffat
  • 3,165
  • 1
  • 21
  • 34

3 Answers3

1

I actually wanted to make the exact same plot last year. I could not find a gnuplot solution (which I am pretty sure exists...), and in the end I wrote a script with an awk part to generate a file with RGB colors for a range of wavelengths, and then plotted those in gnuplot with impulses lc rgb variable. I used code from a few SO questions, but cannot remember the original sources. Anyway, using the code below:

#!/bin/bash

        seq 4000 1 7000 | awk '{
            wv=$1/10
            if(wv < 380){
                    rd = -(380. - 440.) / (440. - 380.)
                    gr = 0.0
                    bl = 1.0}
            if(wv >= 380 && wv < 440){
                    rd = -(wv - 440.) / (440. - 380.)
                    gr = 0.0
                    bl = 1.0}
            if(wv >= 440 && wv < 490){
                    rd = 0.0
                    gr = (wv - 440.) / (490. - 440.)
                    bl = 1.0}
            if(wv >= 490 && wv < 510){
                    rd = 0.0
                    gr = 1.0
                    bl = -(wv - 510.) / (510. - 490.)}
            if(wv >= 510 && wv < 580){
                    rd = (wv - 510.) / (580. - 510.)
                    gr = 1.0
                    bl = 0.0}
            if(wv >= 580 && wv < 645){
                    rd = 1.0
                    gr = -(wv - 645.) / (645. - 580.)
                    bl = 0.0}
            if(wv >= 645 && wv <= 730){
                    rd = -(wv - 780.) / (780. - 645.)
                    gr = 0.0
                    bl = 0.0}
            if(wv > 730){
                    rd = -(730 - 780.) / (780. - 645.)
                    gr = 0.0
                    bl = 0.0}
            rgb=int(255*rd)*2^16+int(255*gr)*2^8+int(255*bl)
            printf("%7.4f %f %f %f %f %3d %3d %3d %10d\n",$1/10000,41,rd,gr,bl,rd*255,gr*255,bl*255,rgb)
        }' > rgb.tmp



gnuplot << GNU

set term pdf size 7,7 font "courier,16"
set output 'bblaw.pdf'
set encoding iso
set border -1 lw 0.90
set tics front


set style line 1 pt 7 ps 1.50 lt -1 lw 2.5 lc "#608DB6CD"
set style line 2 pt 5 ps 1.50 lt -1 lw 2.5 lc "#60EE6363"
set style line 3 pt 9 ps 1.00 lt -1 lw 2.5 lc "#FFB90F"
set style line 4 pt 5 ps 1.50 lt -1 lw 2.5 lc "#EEEEEE"

set xrange [0.10:1.65]
set yrange [0:41]

set  ytics 5
set mytics 5
set  xtics 0.25
set mxtics 5
set format x "%4.2f"

set ylabel "Intensity (kW . sr^{-1} . m^{-2} . {/Symbol m}m^{-1})"
set xlabel "Wavelength ({/Symbol m}m)"

set label "5000K"       at 0.50,14.0 front font ",15"
set label "5500K"       at 0.45,21.5 front font ",15"
set label "5778K (Sun)" at 0.40,27.0 front font ",15"
set label "6000K"       at 0.45,32.5 front font ",15"
set label "8000K"       at 0.22,39.0 front font ",15"

unset key

# length unit is micrometre
c=3e14 # speed of light
h=6.626e-22 # Planck constant
k=1.38e-11 # Boltzmann constant

# Planck curves
p1(x)=1e-6*2*h*c**2/(x**5*(exp(h*c/(x*k*5000))-1))
p2(x)=1e-6*2*h*c**2/(x**5*(exp(h*c/(x*k*5500))-1))
p3(x)=1e-6*2*h*c**2/(x**5*(exp(h*c/(x*k*5778))-1))
p4(x)=1e-6*2*h*c**2/(x**5*(exp(h*c/(x*k*6000))-1))
p5(x)=1e-6*2*h*c**2/(x**5*(exp(h*c/(x*k*8000))-1))

plot "rgb.tmp" u 1:2:9 not w imp lc rgb variable lw 0.5,\
     p1(x) lw 6, p2(x) lw 6, p3(x) lw 6, p4(x) lw 6, p5(x) lw 6

GNU

rm rgb.tmp

You will get something like this:

output

If you run this bash script on your terminal, it should generate a pdf file and remove any temporary files that were created in the process. Note that you can change the awk script at the beginning, in case you want to move the color scale a bit. In this particular case, I limited the wavelength range to 4000:7000 angstroms by editing the seq command on line three.

Let me know if this solution works for you. If so, I'd suggest you add the awk tag to your question.

Vinicius Placco
  • 1,683
  • 2
  • 14
  • 24
0

You can simply define a palette with the wavelengths and the approximate colors, like here. Then use the colorbox as partial background of the plot.

Script: (works with gnuplot>=4.6.0, March 2012)

### Planck black-body radiation with visible spectrum (approximate)
reset

c = 299792458        # m/s
h = 6.62607015e-34   # Js
k = 1.380649e-23     # J/K

Planck(x,T) = 2*h*c**2/x**5/(exp(h*c/(x*k*T))-1)

set palette defined (380 "black", 400 "dark-violet", 440 "blue",  490 '#00b0c0', \
                     530 "green", 560 "yellow", 620 "red", 780 "black")

set style fill solid 0.4
unset cblabel
unset cbtics
set colorbox horizontal user origin first 380, graph 0 size first 400, graph 1 back
set key noautotitles
set grid x,y front
set xrange[100:2000]

plot for [T=4000:7000:1000] Planck(x/1e9,T) w l ti sprintf("%g K",T) lw 2, \
     (NaN) w p palette  # plot nothing just to get the colorbox
### end of script

Result: (created with gnuplot 4.6.0)

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
-1

Its a bit of a manual solution, but how about a bunch of vertical lines. Here is a start. This linewidth is good for a plot window of 1200,900

set arrow 1 from 0.4,0 to 0.4, 50 nohead lc rgb '#8B008B#' lw 3.5
set arrow 2 from 0.405,0 to 0.405, 50 nohead lc rgb '#7000aF#' lw 3.5
set arrow 3 from 0.41,0 to 0.41, 50 nohead lc rgb '#4800FF#' lw 3.5
set arrow 4 from 0.415,0 to 0.415, 50 nohead lc rgb '#3000FF#' lw 3.5
set arrow 5 from 0.42,0 to 0.42, 50 nohead lc rgb '#1800FF#' lw 3.5
set arrow 6 from 0.425,0 to 0.425, 50 nohead lc rgb '#0000FF#' lw 3.5
set arrow 7 from 0.43,0 to 0.43, 50 nohead lc rgb '#0018FF#' lw 3.5
set arrow 8 from 0.435,0 to 0.435, 50 nohead lc rgb '#0030FF#' lw 3.5
set arrow 9 from 0.44,0 to 0.44, 50 nohead lc rgb '#0048FF#' lw 3.5
set arrow 10 from 0.445,0 to 0.445, 50 nohead lc rgb '#0060FF#' lw 3.5
set arrow 11 from 0.45,0 to 0.45, 50 nohead lc rgb '#0078FF#' lw 3.5
set arrow 12 from 0.455,0 to 0.455, 50 nohead lc rgb '#0088FF#' lw 3.5
set arrow 13 from 0.46,0 to 0.46, 50 nohead lc rgb '#0090FF#' lw 3.5
set arrow 14 from 0.465,0 to 0.465, 50 nohead lc rgb '#00a0FF#' lw 3.5
set arrow 15 from 0.47,0 to 0.47, 50 nohead lc rgb '#00b8FF#' lw 3.5
set arrow 16 from 0.475,0 to 0.475, 50 nohead lc rgb '#00d0FF#' lw 3.5
set arrow 17 from 0.48,0 to 0.48, 50 nohead lc rgb '#00fe8FF#' lw 3.5
set arrow 18 from 0.485,0 to 0.485, 50 nohead lc rgb '#00FFFF#' lw 3.5
set arrow 19 from 0.49,0 to 0.49, 50 nohead lc rgb '#7CFFa0#' lw 3.5
set arrow 20 from 0.495,0 to 0.495, 50 nohead lc rgb '#7CFF80#' lw 3.5
set arrow 21 from 0.5,0 to 0.5, 50 nohead lc rgb '#7CFF60#' lw 3.5
set arrow 22 from 0.505,0 to 0.505, 50 nohead lc rgb '#7CFF40#' lw 3.5
set arrow 23 from 0.51,0 to 0.51, 50 nohead lc rgb '#7CFF20#' lw 3.5
set arrow 24 from 0.515,0 to 0.515, 50 nohead lc rgb '#7CFF10#' lw 3.5
set arrow 25 from 0.52,0 to 0.52, 50 nohead lc rgb '#7CFF00#' lw 3.5
set arrow 26 from 0.525,0 to 0.525, 50 nohead lc rgb '#80FF00#' lw 3.5
set arrow 27 from 0.53,0 to 0.53, 50 nohead lc rgb '#88FF00#' lw 3.5
set arrow 28 from 0.535,0 to 0.535, 50 nohead lc rgb '#90FF00#' lw 3.5
set arrow 29 from 0.54,0 to 0.54, 50 nohead lc rgb '#98FF00#' lw 3.5
set arrow 30 from 0.545,0 to 0.545, 50 nohead lc rgb '#a0FF00#' lw 3.5
set arrow 31 from 0.55,0 to 0.55, 50 nohead lc rgb '#a8FF00#' lw 3.5
set arrow 32 from 0.555,0 to 0.555, 50 nohead lc rgb '#b0FF00#' lw 3.5
set arrow 33 from 0.56,0 to 0.56, 50 nohead lc rgb '#c0FF00#' lw 3.5
set arrow 34 from 0.565,0 to 0.565, 50 nohead lc rgb '#d0FF00#' lw 3.5
set arrow 35 from 0.57,0 to 0.57, 50 nohead lc rgb '#e0FF00#' lw 3.5
set arrow 36 from 0.575,0 to 0.575, 50 nohead lc rgb '#f0FF00#' lw 3.5
set arrow 37 from 0.58,0 to 0.58, 50 nohead lc rgb '#FFFF00#' lw 3.5
set arrow 38 from 0.585,0 to 0.585, 50 nohead lc rgb '#FFcF00#' lw 3.5
set arrow 39 from 0.59,0 to 0.59, 50 nohead lc rgb '#FFA500#' lw 3.5
set arrow 40 from 0.595,0 to 0.595, 50 nohead lc rgb '#FFA500#' lw 3.5
set arrow 41 from 0.6,0 to 0.6, 50 nohead lc rgb '#FF9800#' lw 3.5
set arrow 42 from 0.605,0 to 0.605, 50 nohead lc rgb '#FF8000#' lw 3.5
set arrow 43 from 0.61,0 to 0.61, 50 nohead lc rgb '#FF7000#' lw 3.5
set arrow 44 from 0.615,0 to 0.615, 50 nohead lc rgb '#FF6000#' lw 3.5
set arrow 45 from 0.62,0 to 0.62, 50 nohead lc rgb '#FF5000#' lw 3.5
set arrow 46 from 0.625,0 to 0.625, 50 nohead lc rgb '#FF4000#' lw 3.5
set arrow 47 from 0.63,0 to 0.63, 50 nohead lc rgb '#FF3800#' lw 3.5
set arrow 48 from 0.635,0 to 0.635, 50 nohead lc rgb '#FF3000#' lw 3.5
set arrow 49 from 0.64,0 to 0.64, 50 nohead lc rgb '#FF2000#' lw 3.5
set arrow 50 from 0.645,0 to 0.645, 50 nohead lc rgb '#FF1000#' lw 3.5
set arrow 51 from 0.65,0 to 0.65, 50 nohead lc rgb '#FF0000#' lw 3.5
set arrow 52 from 0.655,0 to 0.655, 50 nohead lc rgb '#FF0000#' lw 3.5
set arrow 53 from 0.66,0 to 0.66, 50 nohead lc rgb '#f00000#' lw 3.5
set arrow 54 from 0.665,0 to 0.665, 50 nohead lc rgb '#e00000#' lw 3.5
set arrow 55 from 0.67,0 to 0.67, 50 nohead lc rgb '#d00000#' lw 3.5
set arrow 56 from 0.675,0 to 0.675, 50 nohead lc rgb '#c00000#' lw 3.5
set arrow 57 from 0.68,0 to 0.68, 50 nohead lc rgb '#b00000#' lw 3.5
set arrow 58 from 0.685,0 to 0.685, 50 nohead lc rgb '#a00000#' lw 3.5
set arrow 59 from 0.69,0 to 0.69, 50 nohead lc rgb '#900000#' lw 3.5
set arrow 60 from 0.695,0 to 0.695, 50 nohead lc rgb '#800000#' lw 3.5
set arrow 61 from 0.7,0 to 0.7, 50 nohead lc rgb '#700000#' lw 3.5
Dan Sp.
  • 1,419
  • 1
  • 14
  • 21