[FieldTrip] Logarithmic plot of power spectrum

Joram van Driel joramvandriel at gmail.com
Mon Jul 6 22:16:45 CEST 2015


Hi Daniel,

Alternatively, you could use contourf instead of the default fieldtrip
plotting function. This function has more flexibility for rescaling of axes
than the imagesc function. From the ft_freqanalysis result, extract a
time-by-frequency matrix, and then simply make your own figure:

figure;
contourf(cfg.toi, cfg.foi,
TFR.powspctrm(chanidx,:,:),40,'linestyle','none');
set(gca,'yscale','log','ytick',[2 4 8 16 32 64]);

The chanidx is the channel you want to plot; the value 40 is the smoothness
of the contours, and here it is plotted without lines between the contours
(default is 'yes'). The set(gca... part changes the y-axis scaling,
irrespective of whether your frequencies were logarithmically spaced in
your analysis.

Chrs,
Joram

On Mon, Jul 6, 2015 at 6:02 PM, Daniel Hähnke <
daniel.haehnke at lrz.tu-muenchen.de> wrote:

> Dear Philip,
>
> you’re right, my question is about the equal spacing of the y-axis.
>
> Thanks for the suggestion! I was just using the same line of thought to
> change the code of ft_singleplotTFR, but your approach is much safer than
> messing around with fieldtrip code ;)
>
> All the best,
>
> Daniel
>
> On 06 Jul 2015, at 17:54, Philipp Ruhnau <mail at philipp-ruhnau.de> wrote:
>
> Dear Daniel,
> you can plot TFRs with logarithmic axes yes, by just using ft_multiplotTFR
> or ft_singleplotTFR with your logspace TF data
> but I think you’re question is about equally spacing the image?
>
> if so you can ’trick’ fieldtrip, or better matlabs imagesc which fieldtrip
> uses to plot, by changing the values in the data.freq field to a linearly
> increasing vector (1:1:numel(data.freq)) and then
> either change the numeric values back in a graphic design software,
> or you change the yticklabels in matlab. see snippets below (just tested
> this quickly so no guarantee)
> hope this helps
> philipp
>
>
>
> %assume you have a dataset 'data' which has a powspectrum field
> % keep the original frequency axis
> orig_freq_axis = data.freq;
> % now create fake linear axis
> data.freq = 1:numel(data.freq);
>
> % plot data with defaults (needs powspectrum)
> cfg = [];
> cfg.channel = 1:10; % average across first 10 channels
> figure; ft_singleplotTFR(cfg, data)
>
> % get the y tick labels, which we can use as index for the original data
> yLabels = get(gca, 'YTickLabel');
>
> % find index and create new labels in a cell of strings
> newYLabels = [];
> for i=1:numel(yLabels)
>   ind = str2num(yLabels{i});
>   newYLabels{i} = num2str(orig_freq_axis(ind));
> end
>
> % now change the current labels to correct labels
> set(gca, 'YTickLabel', newYLabels')
>
>
>
> On 06 Jul 2015, at 16:09, Daniel Hähnke <daniel.haehnke at lrz.tu-muenchen.de>
> wrote:
>
> Dear community,
>
> I feel like this is a very basic question, but I have not found any
> solution here.
>
> I’d like to plot my TFRs with a logarithmic frequency axis, as seen e.g.
> in http://www.pnas.org/content/106/50/21341.figures-only
>
> Is there any way I can do this with fieldtrip? I know that I can
> logarithmically space the frequencies of interest, so this question is
> merely about plotting.
>
> All the best,
>
> Daniel
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
>
> --------------------------
> Philipp Ruhnau, PhD
> CIMeC - Center for Mind/Brain Sciences
> Università degli Studi di Trento
> via delle Regole, 101
> 38123 Mattarello (TN) - ITALY
>
> phone: +39 0461 28 3083
> fax: +39 0461 28 3066
> homepage: http://sites.google.com/site/obobcimec
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>



-- 
Joram van Driel, PhD
Postdoc @ Vrije Universiteit Amsterdam
Cognitive Psychology
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20150706/17e0b7a3/attachment-0002.html>


More information about the fieldtrip mailing list