MATLAB Answers

Trouble controlling x-axis values in stackedplot (or having all plots vertically stacked in tiledlayout for 14 columns)

조회 수: 2(최근 30일)
Christina Diersing
Christina Diersing 2021년 7월 12일
댓글: dpb 2021년 7월 13일
I am working on a project to import and graph EEG data, but I am having trouble using stackedplot (or, alternatively, having 14 tiled plots stacked vertically).
For stackedplot: I want to have Timestamp (or timestamp) as the x-axis and, if possible, I'd like to have the y-axes scaled the same. Also, I eventually want to use findpeaks on the plots. Is this possible in stackedplot, or should I go with the tiled plots?
For the tiled plots: I want the 14 plots vertically stacked on the same x-axis (basically, I want it to look like the stackedplot).
I've attached my Matlab code and the csv file I got my data from. Line 23 is where the plotting starts. (Lines 26 and 27 are my attempt at stackedplot. Everything after line 28 is my attempt at tiledplots)
Thank you so much for your help!

채택된 답변

dpb 2021년 7월 13일
편집: dpb 2021년 7월 13일
tTry=readtable('Try 4.csv');
works just fine per the have to increase the height of the default figure window or it won't display all of them, but will refresh when do enlarge the window.
The timestamp isn't a very conducive variable; what's the encoding to convert to datetime?
findpeaks graphics won't work directly; you would be able to save the peak locations and add the markers, but if want to use some of the more in-depth features like the half-width plots and the like, those will be somewhar more of a challenge.
I've never dived into the detail plotting code to see if it could be munged to plot into an existing axes or not -- hold on works for an existing axes; you can get access to the y-axis properties (limited subset) of the stackdplot object axes, but I do not believe there as an axes handle itself that can be used as a target to add additional information onto the plot...not sure, I didn't try anything here now yet.
If you have ambitions along that route, I think the nexttile route may be the way; you can get an axes handle to each tiled axes from it.
for i=2:width(tTry)
puts them all on the figure (again, you'll have to increase the vertical height) but with the default parameters for findpeaks it finds and draws peak locators at every uptick in each time trace so the plot is just a big blob of down-facing triangles--you'll have to use judicious selection of parameters to only locate peaks of interest.
But, the graphing itself isn't of any real problem it doesn't seem...
  댓글 수: 2
dpb 2021년 7월 13일
Your code for stackedplot didn't define the X-axis variable in the same call as the one that tried to plot the variables--you had two calls, one with variables but no X variable so it used the default row number as the x-variable and a second call that had an X variable but no other variables to plot. The two calls don't know anything about each other so each did what was asked but neither was what you wanted/intended.
There isn't any way to use the tiled layout without a loop -- so what's wrong with that? It is a completely different animal than stackedplot in that each plot is a separate axes; in stackedplot all axes share a single x axis and the code is interfaced to the user by expecting an array of all lines to be placed on a separate axis by variable; it was coded to behave that way whereas the tiled layout is a generic tiling of axes inside a figure with no a priori presumptions about what the user will decide is either the layout nor what will go into each axes. Hence, each of those has to be drawn independently and the only way to get from one axes to the next is via nexttile and it must be called explicitly. It is possible to save the handle of the axes object to be able to refer to later or to address a given axes location, but nexttile is the only way to populate the figure once tiledlayout is called -- any other attempt by using axes() or plot() without nexttile simply reverts the figure back to an ordinary figure and single axes.
To add text of any sort to the label, just concatenate static text or use format string -- it's simplest given already have a cellstr() from the stored variable names to just catenate
ylabel(strcat(extractAfter(tTry.Properties.VariableNames(i),'_'),' (uV)'))
I don't know what is meant by the comment about the tiled layout spacing argument -- it can be either a char() or cellstr() or string() but must be one of the three options. Playing around, one gets more vertical space for each axis by 'none' than either of the other two; they only seem to affect the horizontal spacing between the columns if there are more than one. Since your Q? asked about replicating stackedplot, I just used the one.
tiledlayout wasn't introduced until R2019b while I have R2020b installed, but unless TileSpacing wasn't introduced until R2020x, (which I don't know whether was in original release or not), it certainly should work.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by