How to neatly cut off an extreme value in a plot that compresses the rest of a plot? - matlab

So basically, the graph labeled "Thermal Wind" has an extreme value that compresses the y-values for all the other plots, making it much harder to see any of the individual variations in the other plots. Is there a way to neatly cut off this extreme value? I could just rescale the y limit to a maximum of 40, but then this looks ugly.
As for the alternative I've tried - it's here:

I would recommend trying to plot it on a log scale. The function you'll want to consider using is semilogx, though for completeness I recommend also reading the help file on loglog.
Alternately, you could use subplot to generate multiple plots, one of which is zoomed into a region of interest.

Are the outlier points errors in the data, or do they represent extreme cases?
If they are not valid data, just manually exclude them from the data, plot the graph, and include a text clarification when describing the graph. If they are valid data, then trimming them would misrepresent the data, which isn't a good thing.
Graphs of data aren't art: their main goal isn't to be pretty; it's to provide a useful visualization of data. There are some minimum requirements on appearance, however: the axes have to be labeled, the units have to be meaningful, the different curves have to be visually distinct, etc. As long as your graph has these things, you shouldn't expect to lose marks for presentation.

There are two approaches that I use:
One approach would be transform the data so it will fill the plot nicely. Make the transform so that it wouldn't touch the range - say -10 to +10. In your case you could choose it so that 100 transforms to +15 and -100 to -15.
For clarity you need to then also set and label the y ticks appropriately. And for nice style make sure the line changes slope when it goes over the border.
I plot the data as is. But set the axis limits say from -10 to +10. Where points lay outside I place upwards and downwards triangles along the border to mark in which direction the "outliers" would be. Obviously this is only good when there aren't too many.

Related

Is there a way to increase density of data of scatter data?

I have this x y data:
I would like to increase the density of points by closing small gaps. How do i go about. I still want to preserve the structure of the points.
It depends on what you mean by 'closing gaps'.
if you mean that you want to make the data seem more grouped without actually adding more data points, then you might find the 'LineWidth' argument to be useful. If used currectly it increases the width of each marker in the scatter plot, which will make the data seem more grouped and with less gaps.
to use it, write the scatter code line as follows:
scatter(X, Y, 'LneWidth', width_number)
replace 'width_number' with different values and see the effect.

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

Visually Comparable Plot

So I have to plot certain data (90 sets total) and a single set looks like this.
However when I hold on and plot 90 sets superimposed, it looks just like a patch of multiple colours.
Now what would be the most optimal way to represent the plots that can let us compare them and study the difference. For example (and this is just my thought and I am open to opnions) how can I compare these 90 plots in a Matrix fashion viz.
Is there even better ways to represent such collection of plots instead of just superimposing them?
EDIT: To clear things up, I have 90 graphs that look similar to the first graph and I have to compare them in say, a single page. What would be the best way to do it? Also is subplot the best idea for 90 graphs?
Thanks.
You need subplot(), which allows you to plot multiple figures in one window.
http://www.mathworks.com/help/matlab/ref/subplot.html?requestedDomain=www.mathworks.com

Constructing voxels of a 3D cube in MATLAB

I want to construct a 3D cube in MATLAB. I know that the units of any 3D shape are voxels not pixels. Here is what I want to do,
First, I want to construct a cube with some given dimensions x, y, and z.
Second, according to what I understand from different image processing tutorials, this cube must consists of voxels (3D pixels). I want to give every voxel an initial color value, say gray.
Third, I want to access every voxel and change its color, but I want to distinguish the voxels that represent the faces of the cube from those that represent the internal region. I want to axis every voxel by its position x,y, z. At the end, we will end up with a cube that have different colors regions.
I've searched a lot but couldn't find a good way to implement that, but the code given here seems very close in regard to constructing the internal region of the cube,
http://www.mathworks.com/matlabcentral/fileexchange/3280-voxel
But it's not clear to me how it performs the process.
Can anyone tell me how to build such a cube in MATLAB?
Thanks.
You want to plot voxels! Good! Lets see how we can do this stuff.
First of all: yeah, the unit of 3D shapes may be voxels, but they don't need to be. You can plot an sphere in 3D without it being "blocky", thus you dont need to describe it in term of voxels, the same way you don't need to describe a sinusoidal wave in term of pixels to be able to plot it on screen. Look at the figure below. (same happens for cubes)
If you are interested in drawing voxels, I generally would recommend you to use vol3D v2 from Matlab's FEX. Why that instead of your own?
Because the best (only?) way of plotting voxels is actually plotting flat square surfaces, 6 for each cube (see answer here for function that does that). This flat surfaces will also create some artifacts for something called z-fighting in computer graphics. vol3D actually only plots 3 surfaces, the ones looking at you, saving half of the computational time, and avoiding ugly plotting artifacts. It is easy to use, you can define colors per voxel and also the alpha (transparency) of each of them, allowing you to see inside.
Example of use:
% numbers are arbitrary
cube=zeros(11,11,11);
cube(3:9,3:9,3:9)=5; % Create a cube inside the region
% Boring: faces of the cube are a different color.
cube(3:9,3:9,3)=2;
cube(3:9,3:9,9)=2;
cube(3:9,3,3:9)=2;
cube(3:9,9,3:9)=2;
cube(3,3:9,3:9)=2;
cube(9,3:9,3:9)=2;
vold3d('Cdata',cube,'alpha',cube/5)
But yeah, that still looks bad. Because if you want to see the inside, voxel plotting is not the best option. Alphas of different faces stack one on top of the other and the only way of solving this is writing advanced computer graphics ray tracing algorithms, and trust me, that's a long and tough road to take.
Very often one has 4D data, thus data that contains 3D location and a single data for each of the locations. One may think that in this case, you really want voxels, as each of them have a 3D +color, 4D data. Indeed! you can do it with voxels, but sometimes its better to describe it in some other ways. As an example, lets see this person who wanted to highlight a region in his/hers 4D space (link). To see a bigger list I suggest you look at my answer in here about 4D visualization techniques.
Lets try wits a different approach than the voxel one. Lets use the previous cube and create isosurfaces whenever the 4D data changes of value.
iso1=isosurface(cube,1);
iso2=isosurface(cube,4);
p1=patch(iso1,'facecolor','r','facealpha',0.3,'linestyle','none');
p2=patch(iso2,'facecolor','g','facealpha',1,'linestyle','none');
% below here is code for it to look "fancy"
isonormals(cube,p1)
view(3);
axis tight
axis equal
axis off
camlight
lighting gouraud
And this one looks way better, in my opinion.
Choose freely and good plotting!

how to change axes limits in a 3D matlab plot

I have a 3-D plot which I want to cut somehow to show the most interested part and avoid the flat parts (as shown in the picture the blue and orange parts to be the least). I think that it can be done using change of the axis limits in x but different for x_{back} and x_{front} which means I want to change the limits of x front axis to (-20,20) and x back to (-80,-40). How can I do this?
I think krisdestruction is right, it would be such an infrequently-used feature that it's probably not worth the development time or added complexity for TMW to implement.
But you could kludge it. If you were to rotate your data so that the feature aligns with the axes then you could crop the plot to the region of interest as desired. Then hide the grid and draw a new one yourself.
If you're careful you can arrange it so that you can still use the axis labels at the front, which will save you some time, but if not you can always use text to draw new ones on.
I would rotate the data using a rotational transform matrix, which will be pretty quick, and you might be able to pull the gridlines out of the gca object and apply the rotation matrix to those too, which would save you from having to compute them all explicitly.
If you expect to do this more than once or twice then you could encapsulate it all in a nice function that works out the rotation angle from a given pair of 'front' and 'back' axis limits.
Then you can post it to the file exchange : )