Is it possible to add colorbar properties to a maltlab plot? - matlab

I'd really like to know if there's a way to add the colorbar properties we usually find in surface or mesh, but this time for a simple plot.
Thanx you!

Are you asking how to add a colorbar to a plot? The COLORBAR function does that, but it's really only useful if you have an object in your plot that uses a colormap, like a surface or an image.
For simple line plots, you're probably better off going with a legend.

In addition to what gnovice stated in their answer you can define your own colormap. I would suggest you model it off of a HSV scheme since you're wanting to vary the intensity. That was you can select the color you want and vary just the intensity value of it.

Related

Color faces in trimesh matlab?

I'm plotting a very simple triangle using trimesh in matlab, but I struggle to find a property that could fill the triangle color.
Is there a specific one I'm missing?
The doc page doesn't say much:
https://uk.mathworks.com/help/matlab/ref/trimesh.html
I'm not a big matlab expert, but I'm pretty sure there's a property for this.
You want a mesh? Use trimesh!
You want a surface? Use trisurf!

Vary the color of quivver arrows depending on third value

I am trying to create a pcolor, which has a quiver (representing velocity vectors) superimposed. I've managed to achieve this, but now ideally I'd like to color each quiver error depending on that point's velocity in the z-direction.
I know, of course, that it's possible to change the color of all the arrows, but is it possible to change the color of them independently..?
Thanks in advance,
Adam
Test out quiverc. Looks like it does exactly what you're after.
https://www.mathworks.co.uk/matlabcentral/fileexchange/3225-quiverc
The alternative, hack solution, would be to do a sequence of quiver plots, trigger a hold, redo the quiver plot with n-1 items in it, and iterate. Not pretty, but it would work.

Smooth color plots in Matlab

How do I create smooth color plots in Matlab?
Here is where I am at now. I use the imagesc function and
I send you two images. One of them is smoother and better looking
and that is because I used denser meshgrid to compute the function.
But still, it is discrete looking. How do I make it smooth?
Thank you
Sounds like you need a colormap with more gradation. All the colormap generators accept an argument describing the number of discrete colors to include. Try increasing that number; I think the default is something like 64. For example:
colormap(jet(4096))
You can increase the number even further if you like, but eventually you'll hit the limits of 24-bit color space.
Incidentally, the human eye is most sensitive to color gradations in blue hues, so another thing you could do is choose an alternate colormap.

How to vary the line color of a matlab plot (like colormap)?

I have a 2D space in which a function value is defined (you can think of it as a manifold). Now I plotted the function value using contourf and changed the colormap to something softer than jet. So far it looks quite good.
Now I want to draw a line representing the state over time in my space. That is also possible using the the plot command. But I want some more improvements: There is an additional state that is hidden for now (value 0...50). I would like the line color to change according to this hidden state. So in a sense to apply a separate colormap to the line plotted by plot like for example in a waterfall plot.
Is this (or something similar) possible using matlab?
Thanks
If you want to either use interpolated shading or have the colours change with the colour map, then you want to plot your data as a mesh and set the edgecolor property appropriately. Note that in order to plot it as a mesh, then you will need to duplicate it so that it has a size of at least 2 in each direction.
h = mesh([X(:) X(:)], [Y(:) Y(:)], [Z(:) Z(:)], [C(:) C(:)], ...
'EdgeColor', 'interp', 'FaceColor', 'none');
You may also want to look at the MeshStyle property, if you want to plot multiple lines simultaneously.
This solution is also much nicer than the one used in cline because it only creates one graphics object, rather than n.
Have a look into the cline.m function from file exchange, I think it is exactly what you need.
I can recommend the Colored line entry from the file exchange. It has good feedback and uses the color map to define the displayed colours, I've use it sucessfully on a number of projects.

3D scatterplot colored by Z-Value

I've been googling for a while but couldn't find a solution for my problem. I am an amateur matlab user and I would like to create a 3D scatterplot, for this I have a matrix containing several points in 3D space:
>> size(A)
ans =
2511 3
I was able to create a 3D scatterplot using "scatter3" function, but now I am stuck a bit at color-coding the 3D points.
scatter3(A(:,1),A(:,2),A(:,3));
This will plot the data, but now I would like to add a color coding based on the z-Value...
The colors themself don't matter too much. It could be a rainbow spectrum or a temperature spectrum or whatever. I just would like to colorcode them to distinguish the z-Values of the points.
Can anybody help me with this? Thank you!
You have to give some more arguments to scatter3.
scatter3(X,Y,Z,S,C);
S lets you specify areas for each markers (with a vector) or a single area for all the markers, while C lets you specify color. If C is a vector, its values will be linearly mapped to the current colormap. To change the colormap, call colormap(jet) for example. See the documentation on colormap.
Sorry if that's confusing. Short version:
scatter3(A(:,1),A(:,2),A(:,3),9,A(:,3));
colormap(jet); %# or other colormap