Maybe the problem is that you are using "vecsize" instead of "5" in the call to p.line()?
p.line(vecsize,px,py); versus p.line(5,px,py); I'm guessing that vecsize is not always equal to 5. However it would help if you show all the code, and also the working Python version for comparison. best, -Hazen On 1/21/20 1:38 PM, Xavier Cardil wrote: > Hi, any comment on this ? I really can't find the reason lines seem to > get off viewport box randomly, even after several tries refactoring this > function ... any help would be appreciated ! > > On Thu, Jan 16, 2020 at 4:04 PM Xavier Cardil <cardil.xav...@gmail.com > <mailto:cardil.xav...@gmail.com>> wrote: > > Hi, I am trying to draw boxes following example 32 > <http://plplot.sourceforge.net/examples.php?demo=32&lbind=C++>. I > successfully implemented this on Python, but there is some weird > problem when trying to do it on C++: > > Sometimes, boxes are drawn correctly : > > > 20200116_160142.png > > But sometimes, ( seems random ) this happens : > > > 20200116_155042.png > > Is this something I am missing ? I can't figure out why is this > happening? > > Below is my code, which is really simple. Thanks > > > plstream p; > > const auto hmax = max_element(begin(vec.high), end(vec.high)); > const auto lmin = min_element(begin(vec.low), end(vec.low)); > > vector<int> ivec(vecsize); > > generate(ivec.begin(), ivec.end(), [steps = 0]() mutable { return > steps++; }); > const char *device = "xwin"; > p.start(device, 1, 1); > p.ssub(0, 1); > p.env(0, vecsize, *lmin, *hmax, 0, 0); > > PLFLT px[5], py[5]; > PLFLT wx[5], wy[5]; > PLFLT spacing; > PLFLT xmid; > > spacing = .4;// in x axis units > > for (int i = 0; i < vecsize; i++) { > px[0]=ivec[i]+spacing /2.; > py[0]=vec.open[i]; > px[1]=ivec[i]+spacing /2.; > py[1]=vec.close[i]; > px[2]=ivec[i]+1.-spacing /2.; > py[2]=vec.close[i]; > px[3]=ivec[i]+1.-spacing /2.; > py[3]=vec.open[i]; > px[4]=ivec[i]+spacing /2.; > py[4]=vec.open[i]; > > p.col0(1); > p.line(vecsize,px,py); > > > > _______________________________________________ > Plplot-general mailing list > Plplot-general@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/plplot-general > _______________________________________________ Plplot-general mailing list Plplot-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-general