1D plot with exciting colours

27 次查看(过去 30 天)
Hi there,
I have quite a simple question, simple because I'm sure Matlab can do this easily, I just don't know how.
I want to plot some 1D data - in this case my data is a change in voltage over time. But instead of a plain line plot I want a plot where the space below the line is filled with colour. I don't really care what the colours correspond to, whether it is on a spectrum so that high voltage is coloured red and low is blue, or whether whole sections under high voltage peaks are coloured red (like a spectrogram) I would just like a visually appealing plot that uses some colour map; like this one:
Although I understand that my data are no where near as detailed as this example.
Thanks for any help,
Rod.
EDIT:
As suggested, here are links to my data files...
  2 个评论
Doug Hull
Doug Hull 2013-9-6
This does not look like a 1-d plot to me, it looks like an image. What is the shape (vector, matrix, 3-d matrix) of the data you are trying to visualize?
Right Grievous
Right Grievous 2013-9-7
Hi Doug,
I have basically got 2 vectors, very long, but vectors nonetheless. I'm aware that the example is probably an image - it's an output of the spectrogram function. I gave it more for an example of the colours in use, I'm looking for a 'gradient' of different colours rather than blocks of 2 or 3 colours.
Thanks for your help,
Rod.

请先登录,再进行评论。

采纳的回答

Right Grievous
Right Grievous 2013-9-8
编辑:Right Grievous 2013-9-8
After some fiddling I have found this to be the simplest (and most visually appealing) solution, so I will post it here in it's simplest form for anyone else who seeks out this question/answer.
xdata = 1:1:100; % xaxis - such as time
ydata = rand(1,100); % example data
figure % open new figure
colordef black % give figure black background
patch(xdata,ydata,ydata,'FaceColor', 'interp', 'EdgeColor', 'none'); % create a patch, using x and y coordinates and use the data values themselves for colourmap
% If you want to reflect your data around the xaxis with zero being blue and peaks coloured red then use these lines instead: hold on; patch(xdata,ydata,ydata,'FaceColor', 'interp', 'EdgeColor', 'none'); patch(xdata,0-ydata,ydata,'FaceColor', 'interp', 'EdgeColor', 'none');
A similar solution can also be achieved using the scatter function - where the marker colour is defined as your ydata values. But this approach obviously means it will be a scatter graph...

更多回答(1 个)

A Jenkins
A Jenkins 2013-9-6
I am going to assume you have a 1d vector for time and a 1d vector for voltage. If not, then please answer Doug's comment above.
Otherwise, try this:
% provide 2 arrays for your time and voltage signals
xdata=1:0.1:10; %x axis data (array of time series)
zdata=1./xdata; %z axis data (array of voltage signals)
ydata=0:max(zdata)/100:max(zdata);
[xaxis,yaxis]=meshgrid(xdata,ydata);
zaxis=repmat(zdata,length(ydata),1);
x=reshape(xaxis,1,[]);
y=reshape(yaxis,1,[]);
z=reshape(zaxis,1,[]);
scatter3(x,y,(z>y),100,255*(z>y),'filled');
view(0,90);
  14 个评论
Image Analyst
Image Analyst 2013-9-8
That sounds like a good approach if you can get it working.
Right Grievous
Right Grievous 2013-9-8
编辑:Right Grievous 2013-9-8
I have found a solution which gives quite a nice result (and exactly the effect I was looking for) so I have 'answered' my own question.
However, I have another question - I really want to mirror this data around the xaxis, previously I did this by subtracting the values from zero and plotting on the same figure, but now I'm not sure how to get the colours in reverse too, when I plot it this way now I get blue at the lowest negative number and red at the highest positive, I really want blue at zero and red at high negatives and positives...
EDIT:
I solved this too and added it to my answer. Thanks everybody for the help!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by