How to make ticks equidistant in MATLAB - matlab

I have the plot shown below:
Now the problem is that I need to make the fonts large at the same time, I need to make them clear (disjoint). I do not care about the ratio of spaces between ticks. one solution is to have the spaces equidistant so that I can read the tick labels carefully. Any Idea how i can do that?
Following Yoda's comments I surely do get a better look.
I do not know how to get the aspect ratio but I use the following code
figure('Units', 'pixels', ...
'Position', [100 100 500 375]);
The font size is 16 and I set the Axis as:
axis([-1 1 0 100])

It would be more helpful if you also told us what the aspect ratio is and what font-size you're using. If I try to reproduce it, I get a reasonable looking plot where the labels are easy to read at a fontsize of 16 or 18.
Now, moving the tick marks around or intentionally labeling in a different position can lead to lot more problems in interpretation (for one, the data point will no longer align with the tick) and I wouldn't suggest that approach. In your case however, is 0.33 equivalent to 1/3? If so, you could use 1/2 and 1/3 and save some space. You can set it with
set(gca,'xtick',[-1,-0.5,-0.33,0,0.33,0.5,1],...
'xticklabel',{'-1','-1/2','-1/3','0','1/3','1/2','1'},
and it should look like this:

Related

Matlab: create lines with equal physical length along each axis

I want to make scale bars with ticks, and I want the ticks on the X and Y bars to have the same physical length, regardless of the relative lengths, dimensions, or "modes" of the axes (at least at the time the ticks are created). I was hoping that daspect() would give me the information I need for this, but daspect() seems to be mostly useless for interrogating aspect ratio. For instance, if I generate a plot that Matlab gives an XLim of [0 3.5] and a YLim of [0 1], then daspect() gives [3.5 1 ...] regardless of how I have the figure sized on the screen. That's obviously not accurate or helpful. Is there another function, or maybe a way to make daspect() give useful information without manipulating the plot?
daspect() returns garbage on a typical plot. It's because of the stretch-to-fill feature, which distorts the plot to fill up the figure space, rendering the values in DataAspectRatio inaccurate. Instructions for turning off stretch-to-fill can be found here.
I also found a workaround if you want to leave stretch-to-fit on, which is to temporarily set PlotBoxAspectRatioMode to 'manual,' which has the effect of changing the value of DataAspectRatio to match what is on screen.
figure;plot(0.1:0.1:pi,sin(0.1:0.1:pi))
pbaspect manual
val = daspect
pbaspect auto
Or a safer way to do it if you want a generally useful script (e.g. in case PlotBoxAspectRatioMode is already manual and you don't want to change that) would be:
pbaspectMode = get(gca,'PlotBoxAspectRatioMode');
pbaspect manual;
val = daspect;
set(gca,'PlotBoxAspectRatioMode',pbaspectMode);
I'm not sure whether this will have any intermittent or pernicious side effects, however.
According to The Mathworks support:
The technique of setting bpaspect to manual and then back may be "safe" (although I wouldn't be surprised if there are side effects), but a better way is to divide:
real_daspect = daspect./pbaspect;

How do I make a Matlab plot fill the whole page?

I want to make a plot in Matlab which is twice as tall as it is long. I tried following the advice of this question using Position and PaperPositionMode, like so:
figure
set(gcf,'PaperPositionMode','auto');
set(gcf, 'Position', [0 0 100 200]);
barh(1:20);
print('test', '-dpng');
Annoyingly, this resizes the paper size but not the plot, as below.
Is there any way to make a graph with specified width and height? I'm running this on a headless server so clicking and dragging, or any other GUI-specific solutions, aren't an option. Obviously I don't actually want a 100x200 plot, I just wanted to make the figure small enough to fit nicely into the question.
You might try setting the paper size and units. There's a similar question on Mathworks. Relevant content:
set(0,'defaultfigurepaperunits','inches');
set(0,'defaultfigurepaperorientation','landscape');
set(0,'defaultfigurepapersize',[8.5 11]);
set(0,'defaultfigurepaperposition',[.25 .25 [8.5 11]-0.5]);
where set(0, ...) sets the root graphics system values. You could also use your figure instead. Hope this helps.
Alternative approach reference the documentation for figure(). Uses the units & outerposition properties.
figure('units','normalized','outerposition',[0 0 1 1])
See also the position property for another approach.

Is there any way to "stretch" a given colormap for a larger range?

I'm building a MATLAB program to visualize a simulation of particles clustering.
Our simulation usually runs with around 10000 particles and the clusters might get to be around 5000 particles in size and I wanted to color the clusters by size so i inserted the following code:
a=[1 1 1 500]; %means x=1 y=1 z=1 and clustersize=500
colormap(flipud(pink));
scatter3(a(:,1),a(:,2),a(:,3),repmat(10,numel(a(:,1)),1),a(:,4),'filled','MarkerEdgeColor', 'k')
and after a cluster reaches a certain size it becomes "saturated" and sticks with the same color even when growing to be twice that size.
I've tried using colormap(hsv(1024)); to make a larger color map but that isn't very good for me either since i want to use a uniform gradient from light to dark and now necessarily mess around with lots of various colors, as the aren't distinguishable enough.
Any ideas how to stretch colormap(flipud(pink)); so it'll get saturated only around 5000? or alternatively let me know if there is some other solution that'll give me a higher "dynamic range"
Ok, so while trying to answer Luis Mendo I started making a gif of the simulation, and decided to add a colorbar; to the figure, then I saw that the colorbar stretched itself from figure to figure.
I found the code
lowrange = 1;
highrange = 5000;
caxis manual
caxis([lowrange highrange]);
which I used earlier for another simulation worked to predetermine the colorbar;'s range. this apparently meant the range of the colormap was also "stretched" or used the predetermined range.
Here are two clips from the simulation, one with the caxis fix, and one without, notice how the colorbar changes without the fix, that caused the particles to loop black(saturated) the for most of the simulation, regardless of the cluster size.
simulation without the corrected caxis code
simulation with corrected caxis code

Changing axis values on Matlab figure/graph output?

I have a graph that automatically has x and y axis/values. However, I want to completely get rid of those and put into my own custom values, without changing the appearance of the graph at all.
Currently the x and y scales are pixel coordinates of the image, but I want to get rid of it and make them into centimeters so someone can better understand how large the image is that they are looking at...
You can change the units of an axes with this command:
set(YourAxesHandles,'Units','centimeters');
and then play around with the scaling/values/whatever you want:
set(YourAxesHandles,'XMin',[min max]);
set(YourAxesHandles,'YMin',[min max]);
set(YourAxesHandles,'XTick',[min:increment:max]);
and so on. Is that what you meant?
I found how to do this, check it out if you want:
% I want 8 intervals, so I divide 272 (number of pixels in X)
% by 34 to get 8 splits
set(gca,'XTick',[0:34:272])
% specify the label displayed at each tick mark
set(gca,'XTickLabel',[-4:4])
Thanks a lot, you made me look in the right direction.

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

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.