Objects, palettes and pm3d

Is there an easy way to plot an object (2d) filled with a palette spectrum?

I'm just starting to read about palettes and pm3d in gnuplot this week. And I'm a little confused.

Is there a simple way to construct an object like a rectangle that is filled with colors in the spectrum of the palette i.e. an object with a parameter value fillcolor

specified by the spectrum of the palette? Or will I have to use splot?

I couldn't find anything on the internet and no questions about it here ...

+3


source to share


2 answers


If you want a Powerpoint-esque filled gradient, you can hack it in gnuplot by having a multiplier where one of the plots is a small rectangular splot:

#!/usr/bin/env gnuplot

set terminal pngcairo enhanced rounded
set output 'gradient.png'

set samples 1000 # for smooth gradient

set multiplot

# plot actual data
plot sin(x)

# set up plot for a rectangle with no decoration
set pm3d map
unset border
unset tics
unset key
unset colorbox
set margin 0

set size 0.2,0.3

# creates a left-to-right gradient
set origin 0.6,0.6
splot x

# creates a top-to-bottom gradient
set origin 0.3,0.3
splot y

# creates a bottom-left to top-right gradient
set origin 0.3,0.6
splot x + y

# and so on
set origin 0.6,0.3
splot x - y

unset multiplot

      

Result:



enter image description here

For more inspiration see: http://gnuplot.sourceforge.net/demo/pm3d.html http://www.gnuplotting.org/tag/colormap/

+3


source


After playing around with gnuplot a bit, I found another way to plot gradient filled rectangles if you have a data file that doesn't use multiplot

.

So, if you have a file called data with data like this:

x_i y_i

      

in the i-th column, you can do this in gnuplot:

set view map
set palette
set pm3d explicit map
splot "data" using 1:2:(1) with lines lw 2 lc rgb "your_color", (x<x_min || x>max) || (y<y_min || y>y_max) ? 1/0 : x with pm3d

      

The parameter is important explicit

when setting pm3d: it colors with the palette colors when you issue the command with pm3d

. This way you can color your data with your favorite color. The third argument using

is just the z-value, in which case it is 1. The values x_min, x_max, y_min, y_max

are the coordinates of the vertices of the rectangle.



As an example, I had a file like this

2*pi*i/500 sin(2*pi*/500)

      

where pi

= 3.1415 ... with x_min=1

, x_max=3

, y_min=-0.7

and y_max=0.1

I got this schedule:

Output of the example above

Of course, this can be quite cumbersome compared to @andryas's method because we have to write this long expression with a ternary operator, but for those unfamiliar with it multiplot

, it works too.

0


source







All Articles