How do I make the theta-axis or x-axis change color?
10 views (last 30 days)
Show older comments
Hi everyone,
I am trying to plot a function that takes in values of hues. It would be great if I can dye my theta-axis in polar plot or x-axis in plot according to the hue values. Namely I want my axis to have 256 colors all at once. This was I can easily visualize what color corresponds to what r or y value. Is there a way to do so please?
Thanks, J.
0 Comments
Accepted Answer
Star Strider
on 6 Dec 2017
This is as close as I can get to doing what you want:
x = linspace(0, 2*pi, 256);
y = sin(x).^2;
figure(1)
plot(x, y)
hold on
wdth = 0.005;
hp = patch([x fliplr(x)], [ones(size(x)) -ones(size(x))]*wdth, [0:255 255:-1:0]*100);
set(hp, 'EdgeColor','none')
hold off
colormap(jet(256))
grid
Experiment to get the result you want. The ‘wdth’ variable is the width of the x-axis line.
The patch object will not work with polar axes using polarplot. Apparently, that is one of the polarplot restrictions.
4 Comments
More Answers (1)
Adam
on 6 Dec 2017
Edited: Adam
on 6 Dec 2017
hAxes.XAxis.Color = 'b';
will, for example turn the x axis of an axes handle, hAxes, blue. Obviously you can use an RGB triplet also for more accurate colours. This is only valid for relatively recent Matlab versions, R2015b or later, though.
3 Comments
Adam
on 6 Dec 2017
I'm not aware that you can colour axes multiple colours, but you can create a 'line' along the axes that is multicolour, though also as far as I am aware this cannot be done with a standard line and would have to be done as a 'surface' object (or many joined lines, but that would not be very performant)
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!