Arraging multiple 3D plots - r-plotly

I have created 6 3D plots that I need to include in a research paper. However, I need to all the plots in a grid.
I've been trying the function subplot but all my plots are combining instead of forming a grid. I have tried setting nrows to various numbers but it does not change the layout. Any ideas on how to fix this? Or other functions that may serve the same purpose?
Shows the function for 1/6 plots, then the subplot function. to the right is the output:

Related

How to plot multiple functions in same figure (subplot) in Simulink?

Similar to what we can do with the subplot command in MATLAB to have many plots in a single figure, How can I plot different graphs in same figure using Simulink?
Note:
I am not asking about multiplotting which I already know how to do that using vector concatenate + scope but it gives me overriding plots. I am unable to find a way that I could have a separate subplot for each function.
Any help?
Have multiple inputs for your scope (image shows right-click menu)
Show multiple plots from the layout menu (up to 16x16 plots) of the open scope
VoilĂ , subplots! As per the documentation, the first n traces will be shown in the first n subplots of the layout. Any traces which can't be shown individually will all be grouped within the last subplot.

MATLAB: Plotting 2 figures into 2 axes, in a GUI

I have 2 figures generated that show a 3D cube, and one that shows a net. I have associate these with two axes in a GUI using this:
axes(handles.cube);
axes(handles.net);
What I do not understand is how to transfer the figure into each one.
This is probably very simple, I'm very new and very inept with this piece of software- so any advice is greatly appreciated.
I am not sure if this is what you are looking for, but you can use subplot for plotting two different axes in one window, if this is what you desire:
https://de.mathworks.com/help/matlab/examples/displaying-multiple-plots-in-a-single-figure.html

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

Scatter with 2 y-axes and datetick

I would really appreciate some help.
I have to independent datasets. Each dataset contains two variables: dates (as datenumber) and corresponding data. I need to plot both datasets on one scatter plot with dates on x-axis and two y-axes. I have been trying with the following code:
figure(1);
scatter(x1,y1,'g');
set(gca);
ax1=gca;
set(ax1,'YColor','g');
ax2 = axes('Position',get(gca,'Position'),'YAxisLocation','right', XTick'[],'Color','none','YColor','r');
hold on; scatter(x2,y2,'r');
Now, this gives correct y-axis on the right side, however on the right side I end up with two overlapping y-axes.
Also, I need to change x-axis so that it displays dates as opposed to datenumbers. I've tried to incorporate datetick into the code but it again gives me two overlapping x-axes.
Does anyone know how to go about it?
thank you
I tried your script with your sample input and found no problems. Anyway, here's a solution which uses the matlab function plotyy, which is suited to simple plots like this:
%generate input
x1=[732490 732509 732512 732513 732521 732528];
y1=[7.828 7.609 22.422 14.758 26.258 1.477];
x2=[732402 732403 732404 732404 732433];
y2=[0.693 0.645 0.668 0.669 0.668];
figure(1);
[ax, h1,h2]=plotyy(x1,y1,x2,y2,'scatter');
%set colors manually
green=[0 1 0];
red=[1 0 0];
set(h1,'cdata',green);
set(h2,'cdata',red);
set(ax(1),'ycolor',green);
set(ax(2),'ycolor',red);
%note the 'keepticks' and 'keeplimits' options
datetick(ax(1),'x','yyyy-mm-dd','keepticks','keeplimits');
datetick(ax(2),'x','yyyy-mm-dd','keepticks','keeplimits');
Without the datetick call the plotyy function synchronizes the xticks in the plot. When you call datetick, it recalculates the ticks, unless you explicitly tell it not to, see the option keepticks, and this is seen as two sets of x axes (even though the x coordinates are the same, the ticks are located at different positions). The keeplimits option is needed to preserve the original xlim. It obviously needs some more manual work to get plots like this sufficiently pretty.
Also note that I set the axes and data colors manually: there might be a way to do this more elegantly.
Update: keeplimits originally missing
Update2: changed sample data to correspond to updated question comment

How to reduce the borders around subplots in matlab AND subaxis doesn't work

I've written a GUI that gives a matlab subplot of varying size and I'm looking for a generic way to squeeze the subplots together. Subaxis works for the vertical spacing, but it doesn't affect the horizontal spacing.
What's the simplest way to squeeze them together?
An example of one of the output figures it was produced with the following code in a for loop
subaxis (1+ceil(max(zindex)/5),5,5+i, 'Padding', 0, 'Margin', 0,'SpacingHoriz',0.0001,'SpacingVert',0.009);
It looks like your figure dimensions are way different than the number of plots you have. Subaxis works best if you define your figure size, and you should pick the aspect ratio based on how many plots you have.
in the example you have 13 x 5 subplots, but your figure's aspect ratio is more like 7:13. Hence the vertical plots are close together but there is much horizontal white space.
Before plotting, try defining your figure like:
nRows=13;
nCols=5;
PlotWidth=3; %This is your Plot width in cm.
FigW=nCols*FigWidth;
FigH=nRows*FigWidth; %Note: I'm assuming the plots are square
Figure1=figure(1);clf;
set(Figure1,'PaperUnits','centimeters',...
'PaperSize',[FigW FigH],...
'PaperPosition',[0,0,FigW,FigH],...
'Units','centimeters','Position',[1,9,FigW,FigH]);
and see if your figure spacing looks better. A few notes, if you want to use 'inches' instead of cm that's fine. Also, I don't have any margins on my paper plot (defining the paper-size and paper position is useful for exporting). If you wanted a margin you might try something like:
Mgn=1;
set(Figure1,'PaperUnits','centimeters',...
'PaperSize',[FigW+2*Mgn FigH+2*Mgn],...
'PaperPosition',[Mgn,Mgn,FigW,FigH],...
'Units','centimeters','Position',[1,9,FigW,FigH]);
You can then export using matlab's print command to the format of your choice.