how to plot on position you want in GUI of scilab - user-interface

I wrote a GUI, and I want to plot on the right hand side.
It is not like subplot(2,2,2) or something like that, because I want to plot it on right hand side not on the top of right side. Also it is not like subplot(1,2,2).
How to do this?
I can not find any handle of a gcf.

It depends if you want to create axes on the right side of the gui or, if you want to subplot thoses axes. The following answer does both.
// Lets define a figure with a gridbag layout
fig=figure('layout','gridbag')
// Lets define a frame
frameleft=uicontrol(fig,..
'style','frame',..
'BackgroundColor',[0.2,0.2,0.8],.. // blue so visible
'constraints',createConstraints("gridbag", [1,1,1,1],[1,1],'both','center')) // make it use all the available space
// lets define a right frame : just position it a x = 2, this
// will move frameleft to the left
frameright=uicontrol(fig,..
'style','frame',..
'BackgroundColor',[0.2,0.8,0.2],.. // green
'constraints',createConstraints("gridbag", [2,1,1,1],[1,1],'both','center')) // all the available space from x=2
// then to plot, lets create axes relatives to frameright
a = newaxes(frameright)
// Then all commands works as usual
title('Title')
subplot(1,2,2)
plot2d()
produces

Related

How to change key frame values in GDScript (Godot)?

I am trying to play an animation when a scene is instanced. It is a simple animation that translates y from -5 to 5. The animation plays but it plays at x = 0 and z = 0. I understand this is because the translation values for the respective co-ordinates in the animation are set to 0. I have a spatial node on my player scene that can grab transform info and pass it on to my animated scene, but I do not know how to dynamically change the x and z values of the key frames in script.
This answer contains three solutions to the problem...
Target a sub-property
If I understand correctly you want to animate only the y coordinate, and leave the other coordinates unchanged. That is, you don't want to animate the translation vector. You want to animate the y or the translation, a sub-property. This is possible out of the box, but the UI won't offer it to you.
Start by creating a track from the animation editor. You click on "Add Track", select "Property Track", and then on the object you want, and select translation. Now, while the track is empty (no key frame inserted yet), modify the track name to :y at the end.
The track would have been create with a name such as SpatialNodeName:translation, you are going to change it to SpatialNodeName:translation:y.
Afterwards, when you add key frames, they will be for translation.y. Note: doing SpatialNodeName:transform:origin:y or even SpatialNodeName:global_transform:origin:y also works. Similarly, you can imagine how do it for only rotation or scaling, and so on.
Create custom properties and animate them
I'll also mention that another option is using a Tween node (which are easier to create from code).
And also that both Tween and AnimationPlayer can animate any property. Thus, if you need to animate something that is not available, consider adding a property (see setget).
For example:
export var y:float setget set_y, get_y
func set_y(new_value:float) -> void:
transform.origin.y = new_value
func get_y() -> float:
return transform.origin.y
Then you can add a track for the custom property, and animate it like any other.
By the way, also notice the AnimationPlayer can also have "Call Method" tracks.
Modify the animation
Manipulating an animation from code is also possible. I've seen an example elsewhere. You can call get_animation on the AnimationPlayer to get the animation. Then on the returned animation you can call track_get_key_value and track_set_key_value. However, this rarely what you want to do in practice (unless you are making a Godot addon that creates or modifies animations or something like that).

Arrows on Line Segments

I'm using Segment Plot to show multiple lines on the chart. How can I make these lines have arrows on their ends?
You can do this with some SVG + DOM hacking. You can define a "marker element" that can be placed at the beginning, middle or end of a line (see http://tutorials.jenkov.com/svg/marker-element.html for details on markers).
This means manipulating the SVG generated by Plottable. To get the underlying DOM elements, you need to get hold of the d3 "selection" representing each line.
Add a marker definition to the <svg> element where you are rendering the plot. I am pretty sure plottable won't overwrite entities already inside, but if it does you can always add it after rendering the plot.
Use Segment#entities to get all "PlotEntity" objects from the plot (http://plottablejs.org/docs/classes/plottable.plots.segment.html#entities).
Use the PlotEntity#selection property (http://plottablejs.org/docs/interfaces/plottable.plots.plotentity.html#selection) to get the set of DOM elements representing each segment.
The "Selection" interface is just a d3 selection (https://github.com/mbostock/d3/wiki/Selections). You can then add the appropriate "marker-end" attribute to each element, which should give you the arrow heads you want.
On the off-chance these lines are vertical, I have a super easy hack. Use .symbol() to create a scatter plot where the points are either up or down arrows, and place them at the ends of the segments.
Otherwise, you may have to draw the arrows yourself. You can get the pixel locations of the ends of the segments like this:
locX = xScale.invert(endpointXValue)
locY = yScale.invert(endpointYValue)
And then you could append an arrow shape to the foreground (see the crosshair container in this example)

Removing the raised corners from d3.js axes to create flat axis

D3.js axes typically have "handlebars" on the end of each axis, like this:
Those look nice. But.
How can these be removed to make an axis look flat, like this:
The square ends of the path are sized using either the .tickSize method, in which case the second argument gives the outer tick size and the first the main tick size, or else using the .outerTickSize method. In either case, supply a value of 0 to suppress the ticks.
ticks.tickSize(innerTickHeight, 0);
or
ticks.outerTickSize(0);
Source: page on d3 axes.

Using Cocos2d i need to set a sprite boundaries so it cant go off screen, how do I do this?

im using cocos2d to create a game and i want to set my sprite a boundary so that it cannot go off the screen on the line of x. What code can i use to do this. I dont want the sprite to be bounced back in the opposite direction i just want it to stop.
http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12 explains how to set boundaries.
Shamelessly pasted code follows:
// Create edges around the entire screen
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
_groundBody = _world->CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
b2FixtureDef groundBoxDef;
groundBoxDef.shape = &groundBox;
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0));
_bottomFixture = _groundBody->CreateFixture(&groundBoxDef);
The last line setAsEdge sets the edge :D
However, if you want no bouncing, you can eiter set your moving sprite to
spriteDef.restitution = 0f;
or d that on the edge itself, depending if your moving sprite has to bounce on other stuff or not.

Can MATLAB generate, save, and then load axes into a gui axes object dynamically?

Edited for clarity:
I have a GUI that controls a script that generates approximately 40 plots. I want to display any given plot in the GUI window on demand by selecting its number in a drop-down box. The problem is that the plots take a while to generate so I would rather make them once and then load them as needed into the axes object in the GUI. The plots each have different properties, labels, legends, etc..
I tried generating figures and then saving them and trying to load that into the axes object in the GUI and it did not work.
If I initially make the plots using the axes object in the GUI as the target axes I can't save the plot and the legends, etc..
Is this possible in MATLAB?
If I understand the question correctly, you have a GUI with axes and a callback to plot stuff into the axes. For some reason, e.g. because plotting takes a while, you want to be able to save a specific plot and have the ability to reload it.
The easiest way to deal with this issue is to not put an axes object into your GUI, but to use a two-window GUI, where one window has all the controls, and the other is the figure into which you plot stuff. This is advantageous for several reasons: Saving/loading becomes easy, you have access to the figure toolbar, and you can resize etc the figure as you wish (resizing GUIs is generally hairy). You can store the handle to the axes of the figure in the GUI handle structure via SETAPPDATA and access it via GETAPPDATA. Note that you'll want to put a small check at the beginning of your plotting callback, where you check whether the figure still exists using ISHANDLE on the axes handle, and open a new figure if the check returns false.
If you really want to have an axes object in your GUI, the easiest is to just save the x and y data, as well as other properties of the plot that a user may be able to customize (whether the legend is on, or off, or the legend's position property), so that you can regenerate it on the fly.
If, for some reason it is not sufficient to save just properties, you can generate a hidden figure, and use COPYOBJ to copy the axes and its children to that figure, which you then save. However, this is rather clumsy and might come with all kinds of surprising annoyances.
You need to know the handles of axes within the figure. Otherwise it will be difficult to change the axes properties if the figure contains a newer axes object, because gca will refer to the new axes.
The axes can be accessed post figure generation through the figure object because individual axes of a figure are children of the figure object. The following code snippet may help you.
close all
subplot(2,1,1)
subplot(2,1,2)
hAxes = get(gcf, 'Children')
get(hAxes(1)) %shows axes properties of one axes obj
get(hAxes(2)) %shows axes properties of the other
set(hAxes(1), 'YTickLabel', ['a';'b';'c';'d';'e';'f']) %set an axis property
I'm guessing a bit here, but it sounds like you want to create a GUI with an axes that displays different plots, legends, etc. based on which item of a drop-down menu is selected. If this is right, I'm guessing the problem you are having is that plotting a new set of data in the axes causes the old data to be replaced, leaving you to have to regenerate the entire plot anew every time you select a new menu item.
One way I would consider approaching this problem would be to make use of UIPANELs and the 'Visible' property of graphics objects. You could create one panel per menu item, add an axes to each along with whatever data you wish to plot, then simply toggle the visibility of the panels using the SET command instead of replotting everything when a new menu item is selected. Here's an example:
hFigure = figure; %# Create a figure
hPanelA = uipanel('Parent',hFigure); %# Add panel A to the figure
hAxesA = axes('Parent',hPanelA); %# Add an axes to panel A
plot(hAxesA,1:10,rand(1,10),'r'); %# Plot a red line
text(5,0.5,'hello','Parent',hAxesA); %# Plot some text
legend(hAxesA,'red line'); %# Add a legend
hPanelB = uipanel('Parent',hFigure); %# Add panel B to the figure
hAxesB = axes('Parent',hPanelB); %# Add an axes to panel B
plot(hAxesB,1:10,rand(1,10),'b'); %# Plot a blue line
text(5,0.5,'world','Parent',hAxesB); %# Plot some text
legend(hAxesB,'blue line'); %# Add a legend
Now, you can make panel A visible and panel B invisible by doing the following:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'});
And you can do the reverse (hide panel A and show panel B) by doing this:
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'});
You should notice that toggling between the two panels with their two separate axes is quick and smooth, which likely wouldn't be the case if you had to erase and replot data in a single set of axes every time you wanted to look at a new plot. Creating all the graphics objects you need when the GUI is created, then modifying the visibility (or other properties) as needed with the SET command makes for a more efficient GUI.
Also note that you can still modify object properties even when they are invisible, so (continuing from my example above) I could do something like this:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'}); %# Hide panel B
set(hPanelB,'BackgroundColor','b'); %# Change the color of panel B
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'}); %# Show panel B
And now you should see that the background color of panel B is blue. If you also saved handles to your plotted lines and text, you could update them with new values before making them visible again.

Resources