Drawing black areas in matlab contourf plot - matlab

I am generating a series of plots using matlab contourf. I need to do the following with the resulting figure. From this state:
Make this:
Important note: I know the coordinates of pixels which should be blackened.
The easiest way is possible to use ind2rgb, do the "blackening" manually, then use imagesc and deal with the axes propeerties. But using this I will lose the contourf graphics (e.g. the contour lines).
Any better ideas?

You can manipulate the figure colormap by adding black color to the one you use.
M=colormap;
M=[0,0,0 ; M];
colormap(M)
Now assign to the "should be black" pixels a value smaller than the minimum. This will map this value to the minimum color which is now black.
To assign the value efficiently use subs2ind

Related

How to set a 3D scatter plot to black and white in MATLAB?

I have a binary 3D array that I want to display as a scatter plot in MATLAB, but the default yellow and blue color scheme is atrocious and a black and white plot would suit my purposes much better. However, calling a color in the scatter3() command causes all the points to be that color, and I would like to follow the traditional scheme (0 is black, 1 is white)
I generate the scatter plot simply, like so:
[x,y,z] = meshgrid(1:100,1:100,1:100);
scatter3(x(:),y(:),z(:),5,array(:),'filled')
As a followup question, are there better ways to display a 3D array (in this case, my array is a stack of images)? Or is a scatter plot generally sufficient?

How to fill colors in contour circles in paraview?

I have a triangulation surface, and there is a point data named rhoA on it. I plot rhoA in paraview and plot the contour with just one contour value. So you can see many circles on the surface.
But what I need is to fill red colors in the circles and don't show other parts. So how to do it in paraview?
Use the Clip filter and set the Clip Type to Scalar. Set the Scalars property to rhoA and set Value to your threshold value. This filter will cut cells, giving you a more precise surface than the Threshold filter will.
Here is an example of the results you can expect doing this:
You can either :
Use the banded countour filter from VTK, that you will need to expose with a XML only plugin first (hard but precise and efficient)
Use treshold filter (the cut will not be on the contour, whole cells will be extracted)

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.

Smoothing matlab plot figures

I have obtained the following figure using a 120x120 matrix and the surf function.
Is there a simple way to make the lines between different colors look smoother?
First of all, surf may not be the best way to display 2D-image - if you don't actually need the height information, imagesc will work just fine. Even better, it won't show the differently colored lines between hexagons, since it's not going through the colormap at intersections.
However, regardless of your approach, a low-resolution bitmap will not be automatically transformed into a "arbitrary"-resolution vector graphics - and you may not want that, anyway, if you use the figure to allow you to inspect at which combination of (x,y) you obtained at a given value.
There are three approaches to make your image prettier - (1) segment the hexagons, and use patch to create a vector-graphics image. (2) upsample the image with imresample. (3) create a RGB image and smoothen each color separately to get softer transitions:
%# assume img is your image
nColors = length(unique(img));
%# transform the image to rgb
rgb = ind2rgb((img+fliplr(img)),jet(nColors)); %# there are much better colormaps than jet
%# filter each color
for i=1:3,rgbf(:,:,i)=imfilter(rgb(:,:,i),fspecial('gaussian',9,3),'replicate');end

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.