stack histogram

72 views
Skip to first unread message

Etienne DELAY

unread,
Dec 10, 2015, 1:52:54 PM12/10/15
to GAMA
Hi All,
I would like to stack histogram (like in PNG file in attachement) for plot many value in a same `chart`

at this point I have that :

display Barplots {
                chart "Zone U 0.5" type: histogram background: rgb("white") size: {0.5,0.4} position: {0, 0} {
                loop ag over:  commune {          
                                       data "com"+ag.nom_raccourci value: (ag.U_0_5c * 0.04) color: #orange;
                                       data "com"+ag.nom_raccourci value: (ag.U_0_5c * 0.04) + (ag.U_1_5c * 0.04) color: #blue;
                                       data "com"+ag.nom_raccourci value: (ag.U_0_5c * 0.04) + (ag.U_1_5c * 0.04) +(ag.U_maxc * 0.04) color: #green;                 
                              }           
                }
}

Some one can give me a hand ?

thank you in advence :-)

Etienne

gg_age_surface_2005.png

Philippe Caillou

unread,
Dec 11, 2015, 9:45:41 AM12/11/15
to GAMA
Hi,

Thanks, I think you discovered a bug I didn't notice before...
You SHOULD be able to use lists like this:
chart "my_data_chart" type:histogram {
data "A" value:[1,2,3] style:stack;
data "B" value:[2,3] style:stack;
data "C" value:[4,5] style:stack;
}
But I didn't find yet why it doesn't work...

In the meantime (looking into it...), you can use datalist: you give a list of list instead of 3 lists:
chart "my_datalist_chart" type:histogram {
datalist value:[[1,2,3],[1,3],[3,4,5]] style:stack legend:["A","B","C"] categoriesnames:["C1","C2","C3"];
}
It does work, and you can give both names and legends as list (see image below).

I will continue to work to correct the bug...

Philippe

Etienne DELAY

unread,
Dec 11, 2015, 12:46:28 PM12/11/15
to gama-p...@googlegroups.com
Hi Philipe

At this point, I think something is wrong in my loop, and/or I don't know what is a datalist


display Barplots {
               
                chart "Zone U 0.5" type: histogram background: rgb("white") size: {0.5,0.4} position: {0, 0} {
                loop ag over:  commune { 
                                       datalist value:[(ag.U_0_5c * 0.04),(ag.U_0_5c * 0.04),(ag.U_0_5c * 0.04)] style:stack legend:["A","B","C"] categoriesnames:["C1","C2","C3"];               
                              }           
                }
}

An error "Cannot evaluate U_O5c as the target agent is null" :-(

If I try something like

display Barplots {
               
                chart "Zone U 0.5" type: histogram background: rgb("white") size: {0.5,0.4} position: {0, 0} {
                loop ag over:  commune { 
                                       data value:[ag.U_0_5c * 0.04,ag.U_0_5c * 0.04,ag.U_0_5c * 0.04] style:stack legend:["A","B","C"] color: [#orange,#green,#blue];               
                              }           
                }
}

I've not errors but my barplot stay empty ...

E.

Philippe Caillou

unread,
Dec 11, 2015, 2:20:55 PM12/11/15
to GAMA
Hi,

I am not sure you can do loop within charts...
I have at least two solutions without loops:

1) just list management
2) put a reflex in the experiment which will update a list variable used in the chart.

Considering your exemple, the first solution is the simplest, but you can't do the multiplications:
Here is an example:

chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:(ant collect each.name) value:[(ant collect each.val1),(ant collect each.val2)] style:stack;
}

(I put the complete exemple bellow just in case it is not clear, and the result image)

You can create your list of list on the fly, for you something like:

datalist value:[(commune collect each.U_0_5c),(commune collect each.U_0_5c),(commune collect each.U_0_5c)] style:stack legend:["A","B","C"] categoriesnames:[(commune collect each.name)];                



model new

global {
int ants_number <- 4 min: 1 max: 2000 ;
init{  
int a<-1;
create ant number: ants_number{
name<-"ant"+a;
val1<-a;
val2<-a+2;
a<-a+1;
}
}

}
species ant skills: [moving] {
float speed <- 2.0 ;
string name;
int val1<-2;
int val2<-3;
aspect default {
draw shape: circle(1.0) color: #orange ; 
}
}
experiment Ant type: gui {
parameter 'Number of ants:' var: ants_number category: 'Model' ;

reflex update_charts
{
}
output {
display ChartHistoList {
chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:(ant collect each.name) value:[(ant collect each.val1),(ant collect each.val2)] style:stack;
}
}
}
}


2) If you want the multiplications, you can use a list variable:
(in this case you can put your loop in the reflex)

experiment Ant type: gui {
parameter 'Number of ants:' var: ants_number category: 'Model' ;
list<list<int>> myvalues<-[[1,2],[3,4]];
list<string> mynames<-["a","b"];

reflex update_charts
{
myvalues<- [(ant collect each.val1),(ant collect each.val2)];
mynames<-(ant collect each.name);
}
output {
display ChartHistoList {
chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:mynames value:myvalues style:stack;
}
}
}
}

(the result image is the same)

3) If you really want to use loop and data statement, you have to wait for me to correct the bug :)

Philippe

Etienne DELAY

unread,
Dec 12, 2015, 9:49:32 AM12/12/15
to gama-p...@googlegroups.com
Hi Philippe,
Nice! It work so well :-) last problem the labels for x-axe doesn't work. All my communes label are in the 1st bar... the others are with numbers ... :-S
Do you understand why ?

At this point the display look like this :

display Barplots {
               
                chart "Zone U" type: histogram background: rgb("white") size: {0.5,0.4} position: {0, 0} {
                    datalist value:[(commune collect each.U_0_5c),(commune collect each.U_1_5c),(commune collect each.U_maxc)]
                        style:stack legend:[" < 0.5m","0.5 - 1.5m","+1.5m"] categoriesnames:[(commune collect each.nom_raccourci)];    
                       
                }
                chart "Zone AU" type: histogram background: rgb("white") size: {0.5,0.4} position: {0.5, 0} {
                    datalist value:[(commune collect each.AU_0_5c),(commune collect each.AU_1_5c),(commune collect each.AU_maxc)]
                        style:stack legend:[" < 0.5m","0.5 - 1.5m","+1.5m"] categoriesnames:[(commune collect each.nom_raccourci)];    
                       
                }
                chart "Zone A" type: histogram background: rgb("white") size: {0.5,0.4} position: {0, 0.5} {
                    datalist value:[(commune collect each.A_0_5c),(commune collect each.A_1_5c),(commune collect each.A_maxc)]
                        style:stack legend:[" < 0.5m","0.5 - 1.5m","+1.5m"] categoriesnames:[(commune collect each.nom_raccourci)];    
                       
                }
                chart "Zone N" type: histogram background: rgb("white") size: {0.5,0.4} position: {0.5, 0.5} {
                    datalist value:[(commune collect each.N_0_5c),(commune collect each.N_1_5c),(commune collect each.N_maxc)]
                        style:stack legend:[" < 0.5m","0.5 - 1.5m","+1.5m"] categoriesnames:[(commune collect each.nom_raccourci)];    
                       
                }
               
  }

Thank you

Etienne
Capture d'écran de 2015-12-12 15-39-45.png
Capture d'écran de 2015-12-12 15-43-37.png
Message has been deleted

Philippe Caillou

unread,
Dec 12, 2015, 10:14:09 AM12/12/15
to GAMA
Hi,

I think you just have to remove the [] for your name list (you are giving a list of list instead of a list):

categoriesnames:(commune collect each.nom_raccourci)

instead of:

categoriesnames:[(commune collect each.nom_raccourci)]

Tell me if it doesn't work!

Philippe

Etienne DELAY

unread,
Dec 12, 2015, 10:28:46 AM12/12/15
to GAMA
Great ! thank you Philippe! I really need to understand where and when use list and list of list ! :-)

Etienne
Reply all
Reply to author
Forward
0 new messages