Print

Print


Oh wait, somehow I had a "removeAllSeries" in there from an earlier test.
Once removed, your suggestion did the trick. Thanks Joey!!

-Paul

__________________________________________________________
Paul Smaldino, Ph.D.
Assistant Professor, Cognitive and Information Sciences
Faculty Member, Quantitative and Systems Biology Graduate Group
University of California, Merced
http://www.smaldino.com

On Fri, Jun 16, 2017 at 7:17 PM, Paul Smaldino <[log in to unmask]>
wrote:

> OK, that just erased all the plots from the chart frame.
>
>
>
> On Fri, Jun 16, 2017 at 7:13 PM, Joey Harrison <[log in to unmask]> wrote:
>
>> Try adding this line after you call updateSeries:
>>
>> histogram_traits.update(ChartGenerator.FORCE_KEY, true);
>>
>> Joey
>>
>> On Fri, Jun 16, 2017 at 8:37 PM, Paul Smaldino <[log in to unmask]>
>> wrote:
>>
>>> Hi,
>>>
>>> I was hoping someone could help me figure out what's not working with my
>>> code. I have an ABM in which individuals have traits that change over time.
>>> I want to plot a dynamic histogram of all the traits, as well as several
>>> other dynamic plots. Many issues with this, but but using MASON 19 and JRE
>>> 1.8, I can get the plots to appear at initialization, but not they don't
>>> update. I've tried this with scatter plots too, they also don't update
>>> using updateSeries. Time series plots do work, but don't use updateSeries.
>>>
>>> Thanks in advance!
>>>
>>> -Paul
>>>
>>> Below is abridged code (start method only) for histogram.
>>>
>>> public void start() {
>>>    super.start();
>>>    AgentsSimulation as = (AgentsSimulation) state;
>>>    //chart start and step
>>>    histogram_traits.removeAllSeries();
>>>    /*
>>>    * Add data for histograms.
>>>    * Each trait needs to be defined by a vector of doubles
>>>    * for all the values for each agent.
>>>    */
>>>    double[][] traitValueFreq = new double[as.numTraits][as.numAgents];
>>>     for(int i = 0; i < as.numAgents; i++){
>>>         Agent aj = (Agent)as.agentBag.get(i);
>>>         for(int j = 0; j < as.numTraits; j++){
>>>         traitValueFreq[j][i] = aj.traits[j];
>>>         }
>>>      }
>>>      for(int i = 0; i< as.numTraits; i++){
>>>         String seriesName = "Trait " + i;
>>>         histogram_traits.addSeries(traitValueFreq[i],
>>> 51,seriesName,null);
>>>       }
>>>
>>>      if(as.doGraphics) //only update if doing graphics
>>>      scheduleRepeatingImmediatelyAfter(new Steppable() //update all the
>>> plots each time step
>>>      {
>>>         public void step(SimState state)  {
>>>         AgentsSimulation as = (AgentsSimulation) state;
>>>         //update trait histogram
>>>         double[][] traitValueFreq = new double[as.numTraits][as.numAge
>>> nts];
>>>         for(int i = 0; i < as.numAgents; i++){
>>>            Agent aj = (Agent)as.agentBag.get(i);
>>>            for(int j = 0; j < as.numTraits; j++){
>>>               traitValueFreq[j][i] = aj.traits[j];
>>>             }
>>>          }
>>>
>>> //THIS IS THE BIT THAT DOESN’T WORK
>>>       for(int i = 0; i< as.numTraits; i++){
>>>          histogram_traits.updateSeries(i,traitValueFreq[i]);
>>>       }
>>>     }
>>>     });
>>> }
>>>
>>>
>>> __________________________________________________________
>>> Paul Smaldino, Ph.D.
>>> Assistant Professor, Cognitive and Information Sciences
>>> Faculty Member, Quantitative and Systems Biology Graduate Group
>>> University of California, Merced
>>> http://www.smaldino.com
>>>
>>
>>
>