2

How to draw a rectangle filled by visual spectrum color in rectangle in a graph?

enter image description here The rectangle would we plotted like:

set object 1 rectangle from first 6545, graph 0 to first 6580, graph 1 fillcolor "????"

I found the color in this enter link description here.

How to do that please?

Moe
  • 301
  • 2
  • 11

1 Answers1

3

A simple, quick and dirty approach (still to be tuned) would be the following if you just need a rough impression of the color. Make sure that set samples is set high enough such that you have enough impulses and don't get white (background) lines. If you need this spectrum in another graph create an inset with multiplot by adjusting origin and size. Check this in gnuplot with help multiplot, help origin and help size

However, if you need more precise color representation, check the links at the link you gave.

Code:

### visible spectrum ("quick and dirty")
reset session

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

set samples 1000
unset colorbox

plot [380:780] '+' u 1:(1):1 w impulse lc palette notitle
### end of code

Result:

enter image description here

Addition:

Maybe something like this:

Code:

### visible spectrum ("quick and dirty")
# inserted into another plot
reset session

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

set samples 1000
unset colorbox

set multiplot 
    plot cos(x)+0.2*x

    set origin 0.05,0.75
    set size 0.45, 0.2
    unset tics
    plot [380:780] '+' u 1:(1):1 w impulse lc palette lw 1 notitle

unset multiplot
### end of code

Result:

enter image description here

Another variation:

Code:

### visible spectrum ("quick and dirty")
# below curve
reset session

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

set samples 1000
unset colorbox

f(x) = sin((x-380)/25)*cos((x-580)/10) + 2

plot [380:780] '+' u 1:(f(x)):1 w impulse lc palette notitle, \
     f(x) w l lw 2 lc rgb "black" notitle
### end of code

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72
  • 1
    Thank you very much and how to connect it with another graph? Is there easier way than multiplot? – Moe Dec 08 '19 at 20:47