Reputation: 60
In J programming, I had several lines of plot codes, either plot or pd 'show', but the output is only the last plot. How should I solve this? Thank you!
x =: 1 2 3 4 5 6 y =: 2 3 4 5 6 7
z =: 4 6 7 9 5 3
I know putting both into one graph is like x;y,:z
But I want to output two plots like: plot1 is x;y plot2 is x;z
But everytime I run the code, I only got x;z shown
Upvotes: 1
Views: 124
Reputation: 4302
What is happening here is that the plot window is being reused. I think that this is intentional to relieve the user from having to clean up each plot that is created after it has been viewed.
The way around this is to use the object oriented aspect of J so that each window is treated as a separate object. Ric Sherlock gives a good description of this at https://code.jsoftware.com/wiki/Plot/Class , but try the following answer to see if it works for you.
x =: 1 2 3 4 5 6
y =: 2 3 4 5 6 7
z =: 4 6 7 9 5 3
a=: conew 'jzplot'
b=: conew 'jzplot'
plot__a x;z
plot__b x;y
and after you have closed the windows, clear out the locales which support the objects with
codestroy__a ''
1
codestroy__b ''
1
Object oriented programming is covered well in the labs in J and if you are not familiar with it, it would be worth a look to understand the technical details of the above code.
Upvotes: 2