Page 1 of 1

bar graph negative values

Posted: Mon Mar 25, 2019 2:31 pm
by BT454
hi,
Is there piece of code that allows for negative values in a bar graph to start at zero at the y-axis and extend downward, while allowing positive values to start at zero at the y-axis and extend upward?
Thanks,
Bob

Re: bar graph negative values

Posted: Mon Mar 25, 2019 2:53 pm
by EViews Gareth
Isn't that just the default behaviour?
2019-03-25_145223.png
2019-03-25_145223.png (19.46 KiB) Viewed 1033 times

Re: bar graph negative values

Posted: Mon Mar 25, 2019 2:59 pm
by BT454
Thanks,
Does it matter if I'm plotting 2 series?
Is there anything in this code that would prevent this graph from looking like yours?
I've attached a workfile so you can see the graph, and the series behind it.
Thanks again,
Bob

group g iwusl48 hddusl48
freeze(HDDvsIW) g.bar
HDDvsIW.setelem(1) axis(l)
HDDvsIW.setelem(2) axis(r)
HDDvsIW.axis overlap
HDDvsIW.setelem(1) fcolor(green) lwidth(2.5)
HDDvsIW.setelem(2) fcolor(gray) lwidth(2.5)
HDDvsIW.addtext(t) Weekly heating degree-days vs injections/(withdrawals) from storage
HDDvsIW.name(2) Heating degree-days (population weighted)
HDDvsIW.name(1) Injections/(withdrawals) from storage Bcf
HDDvsIW.setfont axes("arial", 14)
HDDvsIW.setfont text("arial", 14, +b)
HDDvsIW.setfont legend("arial", 14)
HDDvsIW.addtext(r, "arial", 14, +b) "Heating degree-days"
HDDvsIW.addtext(l, "arial", 14,+b) "Bcf"

Re: bar graph negative values

Posted: Mon Mar 25, 2019 3:43 pm
by BT454
FWIW, the issue seems to occur after declaring which element will be oriented to which axis (left or right). In other words, if I remove the lines of code:
HDDvsIW_{%x}.setelem(1) axis(l)
HDDvsIW_{%x}.setelem(2) axis(r)
then the orientation of data would be correct. However, I lose the scale and values of the right axis.
Thanks again,
Bob

Re: bar graph negative values

Posted: Mon Mar 25, 2019 4:02 pm
by EViews Gareth
Yeah, so what you want is a sort of hybrid - you want them on different axis, but you want those axis to have continuous values - the 0 on the left axis is in the same place as the 0 on the right axis.

Isn't a way to do that.

Re: bar graph negative values

Posted: Mon Mar 25, 2019 4:47 pm
by BT454
Ok. Thank you.
I think I'm pretty close to figuring out a work around:

evaluate max and mins of both series
!z=@min(x)
!zz= @max(x)
!x=@min(y)
!xx=@max(y)

use if/then/else to determine absolute max/min between both series combined:
if !z<!x then
!zy = !z
else
!zy = !x
endif
if !zz>!xx then
!yz = !zz
else
!yz = !xx
endif

use those scalars to set range:
mygraph.axis(l) range(!zy,!yz)

and then mirror the left axis:
mygraph.axis mirror

This creates a range that is equal for both series and mirrors it across both left and right axis.
Thanks again for all the help (with all eviews matters, not just this one).
have a good night!
Bob