I currently have a contour plot, just like this one here
http://www.originlab.com/www/helponline/Origin/en/mergedProjects/Tutorial/images/Contour_Plot_with_Major_and_Minor_Levels_Filled_by_Using_Color_Palette/Graph_Gallery_Contour_Plot_Palette_16.png,
now I want to add some simple plots of functions in the length width plane, like f(width) = width^n and so on, but I don't know how to overlap these two plots.
So, you want to retain the current graph when adding new graphs: use hold on. See http://www.mathworks.nl/help/matlab/ref/hold.html.
Related
Suppose I have two plots on the unit sphere in Matlab. I would like to be able to match the two plots in the following sense: I want to overlap them and see if I have the same thing. In order to do this I would like to fix one of the plots and rotate the other by hand.
Is it possible to do this in Matlab: rotate a part of the plot while keeping another part fixed?
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')
For Example Here is a Bar plot for some data i was comparing. i was wondering if i could add XTickLable both above and below the X-Axis. It would clarify the plot a lot more.
i have tried many things like
set(gca,'XTickLabel',models(:,1),'XTick',1:numel(models));
hold on
set(gca,'xaxisLocation','top')
set(gca,'XTickLabel',models(:,1),'XTick',1:numel(models));
Copy the axes, link them (for zoom, panning...), and flip to the top the 'XAxisLocation' of the copied one:
h = copyobj(gca,gcf);
linkaxes([gca,h])
set(h,'XAxisL','top')
The MATLAB surf plot below is essentially two plots plotted adjacent to each other. For clarity, I have included some code below used to prepare the plot:
band1 = horzcat(band1, eSurface2(:,:,1));
band2 = horzcat(band2, eSurface2(:,:,2));
surf(band2,'DisplayName','band2');
surf(band3,'DisplayName','band2');
I would like for the y axis numbering to restart at the start of the second graph. How do I go about doing that?
You can use the 'YTick' and 'YTickLabel' properties of the axis to control the ticks, this way you can make it start from zero for the second graph. It will require some trail and error to get it right. See the relevant doc here (you'll have to scroll all the way to the bottom of the page).
Take advantage of the following feature of 'YTickLabel': "If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels".
I have a task to draw electrostatic field between
two electrodes( at given sizes and shape ),
what i have now is that i draw the electrodes with area plot (area(elect_x,elect_y))
the graph looks like this:
------------------.---
|..
.---. |..
|...| |..
.----....| |..
|........| |..
----------------------
and now i would need to draw inside this probably a mesh, showing the field.
Is there any way to do it, or i´m on a wrong way?
Thank you very much for every guide
First, if you want to overlay multiple plots in the same axes, type
hold on
before you plot the second graph (or set the 'NextPlot' property of the axes to 'add'), so that the first plot is not erased when the second one is drawn.
To show electrical field, you may want to have a look at quiver, so you can visualize both direction and strength of the fiels. Also check out is demo of quiver to get and idea how you could show field strength with colors.