Modify graph axis

For tips, questions and general information about writing Add-ins, how to package them, and how to submit them to EViews for publication.

Moderators: EViews Gareth, EViews Moderator

hakperest
Posts: 8
Joined: Thu Jul 02, 2015 6:39 am

Modify graph axis

Postby hakperest » Fri Sep 11, 2015 4:08 am

Hello ,
I have a graph that was plotted

Code: Select all

graph gr.line
command. I want modify bottom axis that should be as like as following image. Bottom axis may contain only ordered number (without zero or decimal pointers). How can I do that?

Thanks
Huseyin
Image

EViews Jason
EViews Developer
Posts: 669
Joined: Tue Sep 16, 2008 3:50 pm

Re: Modify graph axis

Postby EViews Jason » Fri Sep 11, 2015 8:56 am

We are going to need more context. If you have an undated workfile this should already happen, unless I am completely missing what you are asking.

Posting your workfile or an example workfile would be helpful.

hakperest
Posts: 8
Joined: Thu Jul 02, 2015 6:39 am

Re: Modify graph axis

Postby hakperest » Sat Sep 12, 2015 12:44 pm

My code is:

Code: Select all

 graph gr_multi.line(a)  new
gr_multi.shade(shade, left) 0
gr_multi.options linepat
gr_multi.setelem(2) lcolor(black) lwidth(2) lpat(1)

and my file is attached.
I need my graph be scaled automatically.
Ploted series have restricted sample and contains only 40 length then bottom axis should be start with zero and continiues until 40.
Attachments
eviewstest.wf1
(20.23 KiB) Downloaded 237 times

EViews Jason
EViews Developer
Posts: 669
Joined: Tue Sep 16, 2008 3:50 pm

Re: Modify graph axis

Postby EViews Jason » Mon Sep 14, 2015 9:38 am

You will have to create a series with the desired labels and then create a XY line graph.

Code: Select all

load eviewstest
series trend=@trend
series index = trend-@first(trend)  'create an index series starting at the beginning of the sample

group mygroup  index new
freeze(gr_multi2) mygroup.xyline

hakperest
Posts: 8
Joined: Thu Jul 02, 2015 6:39 am

Re: Modify graph axis

Postby hakperest » Fri Sep 18, 2015 10:20 am

Your code was great but there is some other problems with this method.
I used following codes and graph shows more timeset. I want it show only bottom axis between zero and 80 but this method shows it within -10 and 90. Where my data includes only zero to 80.

Code: Select all

          %trend=@getnextname("ZZ__trend")
     %index=@getnextname("ZZ__index")
     %mygroup=@getnextname("ZZ__mygroup")
     series {%trend}=@trend
     series {%index} = {%trend}-@first({%trend})-1
     %legendArti=%i+ " +"
     %legendEksi=%i+ " -"
   
 ' graph {%graph}.line {%i}_2_0m -{%i}_2_0m ({%i}_2_0m -{%i}_2_0m)
     group {%mygroup}  {%index}   {%i}_2_0m -{%i}_2_0m ({%i}_2_0m -{%i}_2_0m)
   
      
       freeze({%graph}) {%mygroup}.xyline
      
      {%graph}.shade(shade, left) 0
      {%graph}.options linepat
      {%graph}.setelem(1) lcolor(black) lwidth(3) lpat(2) legend()
      {%graph}.setelem(2) lcolor(black) lwidth(2) lpat(1)legend({%legendArti})
      {%graph}.setelem(3) lcolor(red) lwidth(2) lpat(1) legend({%legendEksi})       
      {%graph}.setelem(4) lcolor(red) lwidth(1) lpat(2) legend(diff)
      {%graph}.setelem(5) lcolor(red) lwidth(1) lpat(2)legend()
      {%graph}.setelem(6) lcolor(red) lwidth(0) lpat(2) legend()
      {%graph}.options size(4,2) -inbox
      {%graph}.legend position(botcenter)


Image

EViews Jason
EViews Developer
Posts: 669
Joined: Tue Sep 16, 2008 3:50 pm

Re: Modify graph axis

Postby EViews Jason » Fri Sep 18, 2015 4:05 pm

Your sample code does not run for me. I am missing some series such that the following line gives an error

Code: Select all

 group {%mygroup}  {%index}   {%i}_2_0m -{%i}_2_0m ({%i}_2_0m -{%i}_2_0m)


In any case, in your code you also have

Code: Select all

series {%index} = {%trend}-@first({%trend})-1


Did you mean to add the '-1'. If you remove it I believe it will fix the problem

hakperest
Posts: 8
Joined: Thu Jul 02, 2015 6:39 am

Re: Modify graph axis

Postby hakperest » Sat Sep 19, 2015 2:16 am

Thanks a lot. My problem solved with changing smpl :)

Bu I found an bug about plotting with xyline command.
xyline command ignores first series when it plot and colourized but start from first (trend in this example) when legend command is used.

Code: Select all


%graph="linegraph"
d {%graph}
graph {%graph}.line x1 x2 x3 
        {%graph}.shade(shade, left) 0
        {%graph}.options linepat
        {%graph}.setelem(1) lcolor(black) lwidth(2) lpat(2) legend(x1)
        {%graph}.setelem(2) lcolor(black) lwidth(2) lpat(1)legend(x2)      
        {%graph}.setelem(3) lcolor(red) lwidth(2) lpat(1) legend(x3)


  group  mygroup  trend  x1 x2 x3 


   %graph="xylinegraph"   
       freeze({%graph})  mygroup.xyline


        {%graph}.shade(shade, left) 0
        {%graph}.options linepat
        {%graph}.setelem(1) lcolor(black) lwidth(2) lpat(2) legend(x1)
        {%graph}.setelem(2) lcolor(black) lwidth(2) lpat(1)legend(x2)      
        {%graph}.setelem(3) lcolor(red) lwidth(2) lpat(1) legend(x3)    
Attachments
test.wf1
(36.71 KiB) Downloaded 242 times

EViews Jason
EViews Developer
Posts: 669
Joined: Tue Sep 16, 2008 3:50 pm

Re: Modify graph axis

Postby EViews Jason » Tue Sep 22, 2015 8:07 am

Trend isnt being ignored, it is the x axis. So it will not appear as another line. You are graphing trend vs x1, trend vs x2 and trend vs x3. So this appears correct.

Because Trend is the first element in the group, when setting the legend labels for the other series you have to skip Trend. This I admit may not be intuitive but I think you want

Code: Select all

{%graph}.setelem(2) lcolor(black) lwidth(2) lpat(2) legend(x1)
        {%graph}.setelem(3) lcolor(black) lwidth(2) lpat(1)legend(x2)     
        {%graph}.setelem(4) lcolor(red) lwidth(2) lpat(1) legend(x3)


Return to “Add-in Writing area”

Who is online

Users browsing this forum: No registered users and 2 guests