[Scilab-users] ?==?utf-8?q? ?==?utf-8?q? ?= density in a grap

Antoine Monmayrant amonmayr at laas.fr
Fri Jan 24 16:21:40 CET 2020


Hello,

Well for the pixelated version, it needs a bit of coding that depends on the details of your specific case.
But here is a short example of the alternative method: generate an svg file and modify it afterwards to add opacity info.
The key idea is to set the color of the lines we want to set 1/2 transparent to something unique in the graph (like not white or black or some other color that are usually present in the axis) and later search the svg file for this specific color and add opacity.

Hope it helps,

Antoine

////////////////////////////////////////////////////////////////////////

cd('~');

// change here the color for any color that will be different from all other
// colors in the graph
colorStr="(10,10,10)"
opacity=0.3;//final opacity in the svg [0,1], 0 means transparent, 1 opaque

// the text that will appear in the generated svg and for each line
searchStr="stroke:rgb"+colorStr+";";
// we need to add the opacity info
replaceStr="stroke:"+colorStr+";stroke-opacity:"+string(opacity)+";";

// string to be executed after each plot of one of the line we want to be
//  1/2transparent
setLineStr="e=gce();e.children.thickness=10;e.children.foreground=color"+colorStr;

//dummy data
x=linspace(-1,1,10);

// the graph with overlapping lines
f=scf();
plot(x,x,'r')
execstr(setLineStr)

plot(x,-x,'b')
execstr(setLineStr)

plot(x,0.5*ones(x),'b')
execstr(setLineStr)


plot(x,-0.5*ones(x),'b')
execstr(setLineStr)

plot(0.5*ones(x),x,'b')
execstr(setLineStr)

plot(-0.5*ones(x),x,'b')
execstr(setLineStr)

xs2svg(f,"test.svg")

//read the generated svg file
fd = mopen('test.svg', 'rt')
svgTxt=mgetl(fd)
mclose(fd);

// add the transparency info
// can also alter all the line properties (color, width, ...)
newSvgTxt = strsubst(svgTxt, searchStr, replaceStr)

// write the new svg file with 1/2transparent lines
fd = mopen('test_transparency.svg', 'wt')
mputl(newSvgTxt,fd)
mclose(fd);

//////////////////////////////////////////////////////////////////////// 
 
 
Le Vendredi, Janvier 24, 2020 10:34 CET, Jean-Philippe Grivet <jean-philippe.grivet at wanadoo.fr> a écrit: 
 
> Le 24/01/2020 à 08:45, Antoine Monmayrant a écrit :
> > That's what I understood, but using lines, not polygons.
> >
> > Another approach than what I suggested previously would be to pixelate everything: ie make a big matrix for the whole graph and increment the value stored at a certain coordinate whenever it falls under one of the lines.
> > You could then plot this matrix using matplot of sgrayplot... with a graycolormap (maybe reversed graycolormap).
> > Far from ideal, but it would work.
> >
> > Antoine
> >   
> >   
> > Le Jeudi, Janvier 23, 2020 21:27 CET, P M <p.muehlmann at gmail.com> a écrit:
> >   
> >> something like this...only in gray?
> >> [image: test.png]
> >>
> >> Am Do., 23. Jan. 2020 um 19:08 Uhr schrieb Antoine Monmayrant <
> >> amonmayr at laas.fr>:
> >>
> >>> Hello Jean-Philippe,
> >>>
> >>> I think I understand what you want to do, but there is no easy way to get
> >>> this in scilab.
> >>> The main issue is that scilab does not support transparency.
> >>> Otherwise, you could just plot your lines in black with 1/32 alpha (or
> >>> 255/32 alpha if 0 means transparent and 255 solid color).
> >>> For this kind of plot, I usually plot everything in scilab with a dummy
> >>> color (let's say blue), export in svg, edit the svg to replace the dummy
> >>> color by the transparent one.
> >>>
> >>> Antoine
> >>>
> >>>
> >>> Le Jeudi, Janvier 23, 2020 16:35 CET, Jean-Philippe Grivet <
> >>> jean-philippe.grivet at wanadoo.fr> a écrit:
> >>>
> >>>> Dear all,
> >>>>
> >>>> I am drawing a graph in a gray scale (say from 1 to 32), using lines of
> >>>> different density. I would like that, in the region of intersection of
> >>>> two lines, the shade of gray be the sum of the densities of each line.
> >>>> How can I manage that ?
> >>>>
> >>>> Thanks in advance for any hint
> >>>>
> >>>> JP Grivet
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> users mailing list
> >>>> users at lists.scilab.org
> >>>> http://lists.scilab.org/mailman/listinfo/users
> >>>>
> >>> _______________________________________________
> >>> users mailing list
> >>> users at lists.scilab.org
> >>> http://lists.scilab.org/mailman/listinfo/users
> >>>
> > _______________________________________________
> > users mailing list
> > users at lists.scilab.org
> > http://lists.scilab.org/mailman/listinfo/users
> 
> This approach looks rather easy to me. Have you a suggestion on how I 
> can define the pixels to be modified ?
> 
> Than you all for your suggestions
> 
> JP Grivet
> 
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>




More information about the users mailing list