Google Ads

October 19, 2021

Extracting / retrieve plot data in Scilab

Oftentimes you would like to extract data points from the plots as this is extremely useful to do so especially in Engineering and Science analysis. This is especially the case when we are manipulating plot data using some editing method. A similar application MATLAB has a function that allows synchronising of what is being shown in the plotting window to what is stored in the variables. But this function is buggy and can oftentimes CORRUPT the original data stored as unique variables for later processing. Also, it is a good practice not to modify the original variables for comparing with the plot data later. In Scilab, it is really simple to extract information about what is being shown in the plot window as Scilab stores everything in the plot as different object variables which are easily accessible from the Scilab console command prompt. Just with the help of few statements in the command prompt we can easily dump the plot data into the console and copy them over to a spreadsheet or any other editor for saving the plot data separately. Let's assume we have plotted some variables Scilab and the plot window show up. Once the plot window shows up and shows the data we can enter the following commands to dump the plot data into the console:

h = gca()

p = h.children

c = p.children

The first command as shown above retrieve and stores a reference to the graphics object which is holding the plot. The subsequent commands get handles of objects residing in the graphics object. The final command dumps the plot data into the console using the handle which points to the plot data object variable. The following figure shows the result where variable y data what plotted and the above commands dumped the plot data into the console:


January 31, 2019

Create a stylish button in GTK+ (Custom widget creation)

Often times we want to create our own form of buttons and widgets when using widget libraries such as GTK+. Although, we could achieve this by creating theme files but sometimes it is just easier to implement such widget using drawing routines available. In this tutorial, I am going to show you how to create a stylish button in GTK+ by not using widget provided button but by using drawing routines available for GTK+ library like shown below:

First, we create four png images for the button for hover, normal, pressed states and mask. We are going to use Cairo library for drawing our button state images into its container. All the functions required for creating this button are part of Standard GTK+ 2 package, so no external dependencies! for the button creation.

Second, we load button png images using cairo_image_surface_create_from_png function.

Third, we prepare a mask for the button as the button can have any shape where some parts of the button are transparent. We create a pixmap as button mask using gdk_pixmap_new function and format the mask according to mask png file using Cairo drawing functions. Our style button contain would be a GTK+ drawing widget. Finally, we set the mask using gtk_widget_shape_combine_mask function.

Fourth, we have to be able to update the button look according to its state which is achieved by connecting different signals to button container and updating button state variable in the signals callback functions and finally drawing the button images using Cairo functions. The callbacks functions can also be used for achieving normal button operations.

That's it!

Watch the tutorial: