Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

'TreatAs' Optional Parameter

This time we will learn about a quite important optional parameter of fig2plotly, called 'TreatAs'.

'TreatAs' was introduced in fig2plotly in order to help create more complex Charts. To explain a bit, fig2plotly creates the corresponding Chart based on the data structure of the MATLAB figure handler. This is achieved by parsing that structure, getting the necessary data for Plotly to do its magic.

Now, there are some MATLAB functions that create Charts whose figure handler structure does not return the necessary/complete information for fig2plotly to properly parse it. So 'TreatAs' makes this task easy.

It is important to note that not all MATLAB Charts functions need to set 'TreatAs'. Only some of them need it. So far there are few MATLAB functions recognized by 'TreatAs' and it is expected that in the future more functions will be introduced with this important optional parameter.

To illustrate this, let’s turn to the following example:

y2010 = [50 0 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};
t = tiledlayout (2,1);

ax1 = nexttile;
pie3(ax1,y2010)
title('2010')
legend(labels)

ax2 = nexttile;
pie3(ax2,y2011)
title('2011')
legend(labels);

f = fig2plotly(gcf, 'offline', false, 'TreatAs', 'pie3');

By running the above code, MATLAB generates a figure with two really complex pie3 Charts. So by setting 'TreatAs' to 'pie3' in fig2plotly, it can create the corresponding Plotly-Chart, which is really beautiful! :star_struck: Attached below is a screenshot of the Charts obtained.

On the left you can see the Chart generated by MATLAB, while on the right you can see the awesome Chart created by fig2plotly.

Here you can find the link to Chart-Studio so that you can better visualize the Plotly-Chart obtained. By the way, notice how 'offline' was set to false and thus the online mode was activated. This is the reason why I can share the link to Chart-Studio :v:

In future topics I will share more MATLAB functions recognized by 'TreatAs'. Likewise, each function that is introduced in 'TreatAs' will be updated in a future topic.