I am trying to plot a contour with a colorbar that has a small values (10e-9). This value appears at top of the colorbar. How can I change the location of this value from top to bottom of the colorbar. I want to move this value beneath the colorbar because when I added label above the colorbar it overlapped with this value
I attached image for the figure.
You can accomplish what you want by first finding the handle to the color bar, then changing the yticklabel ticklabels property. This is a cell array of stings, one for each tick mark. You can fill in whatever you want to show there. The multiplier at the top will go away. With the text function you can add your own modifier anywhere you want. But I think it looks nicer within the axis label.
However, the simple solution is to change the units you plot. Multiply everything by 10e9 before plotting, then add a nano prefix to your units.
Related
What I really want to do is what this question is all about:
matlab remove only top and right ticks with leaving box on
To paraphrase the original question, I want to have a plot with tick marks on the left and bottom axes but NO ticks on the top and right axes, but with the box outlining the plot still intact.
Since I don't have enough reputation, I wasn't able to simply comment to follow up. Anyway, I execute the same code given in the answer by mc2, and what I get is the figure below. The logic of the method is to use 2 axes that have the same dimensions and overlay them on top of each other. The first axis has the 'box' property turned off, the second one does not. The code is:
a = gca;
set(a,'box','off','color','none')
b = axes('Position',get(a,'Position'),'box','on','xtick',[],'ytick',[]);
axes(a)
Assume that the axis that represents "a" already exists. That's the initial figure. (I added the blacked out part on top of the screen shot.) The second axis that was created is clearly not the same dimensions as the initial one--it's the bigger, nearly-square box that surrounds the smaller, rectangular one. Instead, I want the big, nearly-square box to be same dimensions as the smaller one.
Somehow the get(a,'Position') function is not grabbing the correct dimensions that I want it to. Why is this happening?
I didn't make the original figure myself; a collaborator generated the data and sent me *.fig file.
Is there any way in Matlab to specify that the tick marks should appear on top of the graph?
I'm making a plot with shading for when recessions occur. I currently plot a patch object as the farthest back object in a plot, but this obscures any tick marks that occur during this window. For example:
Is there a way to get the tick marks to appear in front of this shading?
assuming you first draw the patch then the bar plot, this is what a solution would look like:
h=gca;
h.Layer='top'
This uses the layer property of the axes to force the bar plot to be on top.
If you have an older matlab version you might want to add this instead:
set(gca,'Layer','top')
I am generating multiple plots of different datasets in succession using MATLAB. I would like the legend positions to be such that they don't overlap on the plotted lines and it would be ideal if this placement could be done automatically.
I am aware of setting the 'Location' to 'best' to achieve this but the placement of the legend tends to be awkward when 'best' is used (below). Also, I would like the legend to be inside the plot. I also came across a way to make the legend transparent (here) so that it does not render the plotted data invisible, but explicitly placing the legend elsewhere is what I am looking for.
Is there a way to place the legend at the extremes of the image ('NorthWest', 'SouthWest' etc) automatically such that it does not overlap on the plotted data (apart from the methods suggested above)?
So, you have tried using Location instead of Position? For example:
x =1:100;
y = x.^2;
lgd = legend('y = x.^2');
set(lgd,'Location','best')
and you are getting odd results correct? A quick way of solving this would be to still use Location, with best, and extract the coordinates:
lgd.Position
You should get something like this:
ans =
0.7734 0.3037 0.1082 0.0200
which maps to:
[left bottom width height]
You will need to focus on left and bottom. These two values, left and bottom, specify the distance from the lower left corner of the figure to the lower left corner of the legend, and they are analogous to the grid frame you are using.
Then, depending on the size of the frame (I would suggest you use axis([XMIN XMAX YMIN YMAX]) for this, if possible), you can pinpoint the position of the legend within the grid. What you can do next, is check if and which of your graphs in the plot cross paths with the legend (maybe define a relative distance function based on some distance threshold) and if they do, then randomly reposition the legend (i.e. change the values of left and bottom) and repeat until your conditions are met.
If this still troubles you I can write a short snippet. Finally, know that you can always opt for placing the legend on the outside:
set(lgd,'Location','BestOutside')
I have the tick label set for the x-axis already and I also have the label set for the x-axis too. I am seeking a way to put an additional x label to the rightmost of the figure next to the x tick labels, is there any way to do so? Thanks
just like the following figure, the x ticks was added automatically and x label was added by the command xlabel. But I want to add one additional label "add'l" (red) in the figure. But I have many plots and/or subplots and the axes might be different, so I need to add that label with problem instead of manually.
I suggest using a uicontrol that will be carefully placed in the relevant area.
uicontrol('style','text',....);
If your UI is resizable, be sure to have the same units, i.e. if the text units are Normalized, then the axes units should be Normalized as well.
Check out this example on the MATPLOTLIB gallery page: http://matplotlib.org/examples/pylab_examples/alignment_test.html
It shows adding all kinds of different text to the axis.
Consider something like
figure
plot(sin(0:0.01:pi))
axis tight
set(gca,'box','on','ticklength',[0.02 0.05])
then export the graph to PDF or whatever. The lines of the graph are on top of the tick labels and the axes. (Furthermore, the lines of the axes don't meet correctly, but that's another story.)
Is there a way (that can be automated) to have the axes drawn on top?
Try:
set(gca, 'Layer','top')
according to the documentation page:
Layer
{bottom} | top
Draw axis lines below or above graphics objects. Determines whether
to draw axis lines and tick marks on
top or below axes children objects for
any 2-D view (for example, when you
are looking along the x-, y-, or
z-axis). Use this property to place
grid lines and tick marks on top of
images.
and to visually see the effect (zoomed in 1200%), I save the figure as a PDF file:
Default (Layer=bottom):
with Layer=top: