Graph triplets

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Graph triplets

Postby tho_mi » Mon Mar 19, 2018 10:51 am

Hey,

I have three variables I'd like to plot. I have observations on variable a and b and the result of a function applied to them, which is variable c. Is there a way to plot all three variables (e.g. something like a heatmap with different colors for each observation depending on the value of variable c)? I only found bubble plots. Is there anything else?

Thanks in advance!

tho_mi
Posts: 61
Joined: Sat May 12, 2012 2:41 am

Re: Graph triplets

Postby tho_mi » Wed Mar 21, 2018 1:01 pm

Update. As far as I see/saw there is no possibility to draw something like a heatmap "automatically". I decided to do the following:
1. Split the data into 5 (e.g.) groups (with respect to variable c). Instead of a 1000x3 matrix (1000 observations, variable a+b+c) I have now a 200x10 matrix (200 observations for each group consisting of variable a+b).
2. Using matrix.xypair it is now possible to draw the observations for each group in different colors (I deactivated the lines and activated the symbols to get a scatter plot).

Now there are three questions:
1. Are there some sort of "color schemes" in EViews? EViews chooses the colors on it's own and it doesn't look like a heatmap. If not, which way would you recommend to get "sensible" colors (without hard-coding them)? I want the code to be flexible with respect to the (number of) groups.
2. I'm a bit confused when it comes to setelem. xypair uses a line graph by default, so I have to change the settings for each element. In my case I have basically five elements (there can't be different symbols for 1 and 2 or 3 and 4), and therefore it would make sense to change the settings for every odd element (I think/thought it wouldn't make sense to change it for 1 and 2, but EViews doesn't share my opinion). If I change the settings for 1 to 5, the graph looks the way I want it to. If I change the settings for the odd elements, then 2 and 4 are still lines.
3. The standard labels are (C1, C2), (C3, C4) and so on. Is there a way to change it to something like "C1 - C2"?

I'll post the code once I'm finished (maybe someone else wants to do something similar).

Best,
Thomas

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

Re: Graph triplets

Postby EViews Jason » Thu Mar 22, 2018 10:26 am

1. There are no predefined color schemes. You can set default colors yourself via Options->Graphics defaults but it is up to you to choose the colors. Since you will have a variable number of groups, you will have manually determine and set the color for each group yourself. To determine the color in RGB units, you can:

1.Open the Options->Graphics default dialog and select Graph Elements->Lines and Symbols.
2.Click the Color box which should bring up the color dialog.
3.Choose a base color (red for example)
4.Write down the Red, Green and blue values
5.Use the slider on the right to adjust the shade
6.repeat step 4 and 5 for the max number of groups

This will give you a set of colors. From here, you can then set within the code the colors for each group. For example, for 3 groups use color #1, #5 and #10, for 10 groups use #1 through #10, etc. Understandably, this is long and tedious but it will get the desired effect.

2.Just so that we are on the same page. Here is a program that takes 3 series (workfile has 900 observations) and creates a matrix containing the 3 series but broken into 3 subseries. It also places the trend (ie the x-axis) series in between each subseries so that we can use 'xypair'.

Code: Select all

create u 900

series t=@trend+1

series ser1 = rnd
series ser2 = 2*rnd
series ser3 = 3*rnd

group g t ser1 t ser2 t ser3

smpl 1 300
matrix first = @convert(g)

smpl 301 600
matrix second = @convert(g)

smpl 601 900
matrix third = @convert(g)

matrix full = @hcat(first, second)
full = @hcat(full, third)

freeze(mygraph) full.xypair

mygraph.setelem(1) linecolor(black)
show mygraph

To answer your question, setelem refers to each pair. It does not refer to each column in the series (for xypairs) like it would in the normal line graph case. Setelem(1) refers to pair 'c1-c2', setelem(2) refers to 'c3-c4'.

3.Unfortunately you cannot.

Going back to question #1 and using my example, you could then add:

Code: Select all

mygraph.setelem(1) linecolor(rgb(255,0,0)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(2) linecolor(rgb(155,100,100)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(3) linecolor(rgb(0,0,0)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(4) linecolor(rgb(255,0,0)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(5) linecolor(rgb(155,100,100)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(6) linecolor(rgb(0,0,0)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(7) linecolor(rgb(255,0,0)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(8) linecolor(rgb(155,100,100)) symbol(CIRCLE) linepattern(none)
mygraph.setelem(9) linecolor(rgb(0,0,0)) symbol(CIRCLE) linepattern(none)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests