1D plot with exciting colours

조회 수: 33 (최근 30일)
Right Grievous
Right Grievous 2013년 9월 6일
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