1D plot with exciting colours

12 views (last 30 days)
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 Comments
Doug Hull
Doug Hull on 6 Sep 2013
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 on 7 Sep 2013
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.

Sign in to comment.

Accepted Answer

Right Grievous
Right Grievous on 8 Sep 2013
Edited: Right Grievous on 8 Sep 2013
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...

More Answers (1)

A Jenkins
A Jenkins on 6 Sep 2013
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 Comments
Image Analyst
Image Analyst on 8 Sep 2013
That sounds like a good approach if you can get it working.
Right Grievous
Right Grievous on 8 Sep 2013
Edited: Right Grievous on 8 Sep 2013
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!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!