Trace a curve with two colors? - plot

is there a way to have a curve with two colors, well i have many curves in my plot. But I like to add a specific characteristic, i want the curve 1 to be simple line in[a,b] interval, and dotted line in interval [b,c].
an example of my graph:
plot exp(-x**2 / 2), sin(x)
can we make sin(x) plotted in dotted line from[0,5]
thanks in advance.

You can specify the line type on a certain interval with the linetype keyword to the plot command. I don't think there is a way to make linetype a function of interval without doing it manually. For example:
plot exp(-x**2/2), [0:5] sin(x) lt 1 lc rgb 'green', [5:] sin(x) lt 2 lc rgb 'green'
gives

Related

Multiple line chart

I am trying to plot two line curves on one chart using plot() and then lines().
But with this the second line curve goes out of chart and is half plotted.
plot(A, main="Bot",xlab="Days",ylab="$$$",type='l',col = 'Green')
lines(B, main="Bot",col = 'Red')
Am I missing any parameter for the scale?
Compute the minimum value for y on the red curve, then add the parameter ylim=c(MinY, 4000) into your first plot.

filling under step functions in gnuplot

I am using Gnuplot to draw step functions from an input file:
plot 'myFile' using 1:2 with steps
I want to fill underneath the plot. something like
plot 'myFile' using 1:2 with filledcurves
But Gnuplot fill underneath the diagram by drawing a line between consecutive points.
How can I fill in underneath the step function?
Use the fillsteps plotting style, which is the same as steps, but the area between the curve and y=0 is filled:
set samples 11
set xrange [0:10]
plot '+' with fillsteps fs solid 0.3 noborder lt 1,\
'+' with steps lt 1 lw 4

Gnuplot color interpolation for set of linear functions

I want to plot N different linear functions in a graph using gnuplot.
Furthermore, I have to colors, lets say red and black.
I want to plot all functions with different colors, so that the first function is red, the Nth is black, and the color of all functions in between is interpolated.
How can I do this using gnuplot?
Note: N is not fixed, so I would like gnuplot to do the interpolation.
Something like this, which I quickly hacked together in Paint:
Here is one possibility to color the lines according to a predefined palette
N=6
set palette defined (0 'red', 1 'black')
f(x, n) = x+n
set samples 100
set style data lines
set key left
plot for [i=0:(N-1)] f(x, i) lw 2 lt palette frac i/(N-1.0) title sprintf('n = %d', i)
linetype palette frac chooses the color from a defined palette using a fractional value. You could also use linetype palette cb to use absolute values.
The result with 4.6.4 is

How to change the colour of the lines in density plot produced from sm.density.compare( ) in R?

I have produced a figure with 4 density plots as shown below, using sm.density.compare in R:
How can I change the colour of the lines? Also of interest is how I can change the type of the line? i.e. dotted, solid
You can use the same parameters as in other base plotting functions - col= for the colors and lty= for the line types.
library(sm)
y <- rnorm(100)
g <- rep(1:2, rep(50,2))
sm.density.compare(y, g,col=c("blue","black"),lty=c(4,6))

How do I select a color for every point in Gnuplot data file?

I want to plot points, each with X, Y and a color. How do I do that in Gnuplot?
You can try something like this:
Line plot in GnuPlot where line color is a third column in my data file?
For example:
plot "./file.dat" u 1:2:3 with points palette
where file.dat contains your data, the first column is the x axis and the second column is the y axis, the third column is the colour.
You could consider looking at the Pyxplot plotting package http://pyxplot.org.uk, which has very similar syntax to gnuplot (albeit cleaned up considerably), and which allows point styles to be specified on a point-by-point basis. For example, in Pyxplot:
plot "file.dat" using 1:2:3 with points color rgb($4,$5,$6)
would take the RGB components for the color of each point from the 4th, 5th and 6th columns of the data file. Alternatively,
plot "file.dat" using 1:2:3 with points color $4
would read the numbers in the 4th column of the data file (call it n), and plot each point with the n-th color from the palette. If n is non-integer, say 2.5, it gives you a color half way between color 2 and color 3 in RGB space.

Resources