Colormap in 2d plots in Scilab - plot

When using the plot(y) function in Scilab, being y a real matrix, multiple data curves are plotted on a 2d plot and the color of each curve is automatically set.
According to Scilab online help, a default color table is used (the command cycles the table and colors each curve accordingly):
http://help.scilab.org/docs/5.5.2/en_US/plot.html
The problem is that the default table lists only 7 colors, so the 8th data curve will have the same color as the 1st, and so on.
Is there a way to extend this table, to automatically color more than 7 data curves with distinct colors?
I tried using the colormap as in 3d plots, but didn't worked.
f = scf();
plot(myData);
f.color_map = jetcolormap(32);
I think this only works for 3d plots.

You can use a for loop to set the foreground color using gce().
Example
clf()
number_of_points=100;
number_of_lines=42;
x=[1:number_of_points]
for line_number = 1:number_of_lines
plot(x, x+line_number);
last_line = gce();
last_line.children.foreground = line_number;
end
f = gcf();
f.color_map= jetcolormap(number_of_lines);
Result

Related

Plot a curve with different color for each point in R

I have a curve, for instance
y_curve=c(1,2,5,6,9,1).
and the colors for each curve point
colors=c("#0000FF","#606060","#606060","#FF0000","#FF0000","#FF0000").
In theory I want to plot a curve where the first half has one color (except for the first point which is blue) and the second half has another color. In my example the dataset has more than 3000 observations so it makes sense.
For some reason, if I plot the data just using the command
plot(y_curve,col=colors), the color of points is plotted corrently.
Nevertheless, if I add the option type="l", the plotted curve has only one color - the blue, which is the first color in the vector colors ("#0000FF").
Does anyone know what am I doing wrong?
So the code is
y_curve=c(1,2,5,6,9,1)
colors=c("#0000FF","#606060","#606060","#FF0000","#FF0000","#FF0000")
plot(y_curve,col=colors,type="l")
Thank you all in advance.
I avoid using ggplot since this part of code is inside an already complicated function and I prefer using the base R commands.
The line option for the plot function does not accept multiple colors.
There is the segments() function that we can use to manually draw in each separate segment individually with a unique color.
y_curve=c(1,2,5,6,9,1)
colors=c("#0000FF","#606060","#606060","#FF0000","#FF0000","#FF0000")
#create a mostly blank plot
plot(y_curve,col=NA)
# Use this to show the points:
#plot(y_curve,col=colors)
#index variable
x = seq_along(y_curve)
#draw the segments
segments(head(x,-1), head(y_curve,-1), x[-1], y_curve[-1], type="l", col=colors)
This answer is based on the solution to this question:
How do I plot a graph in R, with the first values in one colour and the next values in another colour?

R heatmap function - can you add more colours so that differences within large regions are more obvious?

I am plotting a heatmap in R using the base R heatmap() function. Is there a way to define more colours so that the heatmap has a greater variation in the colours used. Currently it is using about 10 and the "hottest" area is quite large and dark purple. I want more colours so that this large area itself it broken down into more colours to better differentiate.
Try experimenting with the color palettes of the grDevices package.
library(grDevices)
heatmap(x, col = topo.colors(n))
where n is the number of colors.
Or, alternatively
col = rainbow(n)
col = terrain.colors(n)
col = cm.colors(n)
However, often the problem with differentiation does not depend on the number of colors, but on the data variability: many of them may be clustered in a small range of values. In such case you could try to differentiate them by chosing a subrange or transforming the data, for example by graphing their logaritm.
Examples:
50 colors from cm.colors palette:
heatmap(Ca, col=cm.colors(50), Rowv=NA, Colv=NA)
matrix of log values, with 50 colors from cm.colors palette:
heatmap(log(Ca), col=cm.colors(50), Rowv=NA, Colv=NA)
in which subtler differences can be seen.

Specifying a specific hex color for individual points in a 3d scatter plot

I have LiDAR dataset on which I've extracted RGB-NIR colors from a raster. I'm having no issues generating the 3d plots in plotly I want to make, or coloring the plot based on a 1-d column of values (such as NDVI); but I'm interested in coloring the points based on an RGB hex code I've written into one of the columns (taken from the raster), but i can't seem to find a way to write this in as a colorspace. While I can call on individual hex codes, it treats them as factors rather than a color specification. What I've figured out that I can do is either a) specify a qualitative color, or b) apply a color ramp. I can't seem to find a way to apply an RGB colorspace to the data.
Is there a way to specify a column in a data.frame (working in R) which has a hex or RGB code associated with each individual point in a plotly scatter plot? Is my only alternative to make a 3 color (R-G-B) color ramp, and map colors to it? Is there any way to get RGB colors to a plotly marker?
stack.exa<-data.frame(X= c(470219.59,470203.74,470215.49,470218.41,470214.88),
Y= c(5013443.99,5013439.34,5013432.39,5013437.72,5013436.6),
Z= c(645.62,629.83,638.78,617.32,639.54),
R= c(49,88,69,68,64),
B= c(76,134,102,97,96),
G= c(69,91,78,75,79),
HEX=c("#314545","#585B5B","#454E4E","#444B4B","#404F4F"))
trace.test<-plot_ly(stack.exa,
x = ~X, y = ~Y, z = ~Z,
color=~HEX,
marker=list(
size = 20,
line = list(color = 'rgba(0, 0, 0, 0)',
width = 0)
)
)
According to ?plot_ly():
color (...) To avoid scaling, wrap with I()
Modifying your code to color =~ I(HEX) seems to work. It's hard for me to tell, though, since all of the colors appear to be very similar to one another (Five Shades of Grey...)

Parallel Co-ordinates Plot in R

I'd like to plot a parallel co-ordinate plot for a dataset mtcars. I want to set a variable on color. I used the code :
library(GGgally)
ggparcoord(data=mtcars, columns=1:10 , groupColumn=11)
It generated the graph but all the lines are in shades of blue. However I have trouble comprehending the graph and making observations due to similar colors used. How can I introduce a different set of colors like blue, green and red etx for the same variable.
You can use the ggparcoord()'s coloring function for this by turning the grouping-column into a factor.
mtcars[,11] <- as.factor(mtcars[,11])
ggparcoord(data=mtcars, columns=1:10 , groupColumn=11)

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