I seem to have made some settings change where all of my MATLAB plots (plot, plot3, surf, etc) show up in this red/green color scale:
I searched around forums and the MATLAB user guide but am not finding anything. It's not a huge deal, as I can enter code to fix this on each plot, but I shouldn't have to.
How to fix this?
Check startup.m you seem to have set your default colormap to autumn or something. Just put it back to either jet (pre 2015a), or parula.
I don't know about the whole settings. These two commands can reset a figure properties (including its colormap) to its default values:
h=gcf;
reset(h)
This way you assign a handle to the last figure you have. Then, the second command resets its options to default values.
Update after Adrian's comment: Check out this page: Default Property Values It clearly shows how is it possible to regenrate the problem you have and you might need use the remove option for removing user-defined default value. There is a factory defined colormap accessible by the function: get(groot,'factoryFigureColormap'). This might help you too.
Related
Simple question: in Matlab R2013, Win7(64) (actually always it was like that) after changes made in colormapeditor one can copy the values of colormap just by typing colormap or get(gcf,'Colormap') or similar. But in the version R2014 I cannot do this - no matter what I change in colormapeditor, I get the same default colormap. See this in Matlab command line:
img=surf(peaks)
colormapeditor
(now, change for instance the limit colors to red). Now use:
colormap
get(gcf,'Colormap')
you got the same default UNCHANGED colormap. However if you close colormapeditor and invoke it again it remembers changed colors.
What I'm doing wrong? Is this :New MATLAB Graphics System" responsible for that?
Thank you for help.
Yacek.
PS:
The same states if you use fig=figure first and than try get(fig,'Colormap') or fig.Colormap etc. The command colormapeditor remembers changes, but one cannot save them.
It looks like the colormap is now associated with the axes rather than the figure. So,
cmap = colormap(gca);
will retrieve the map you're looking for.
I want to add legend to matlab pie instead of just putting the names close the pie itself. That is, I want names to be displayed in a box, and the percentage to be displayed close to the pie (as it usually is). But if I simply add a legend, as follows, it will be not attached to the patches information:
pieH=pie([.3,.4,.3]);
legend({'Leg1','Leg2','Leg3'},'location','EastOutside');
I've tried turning the patch annotation icon display to on, as follows, but it didn't work:
set(get(get(pieH(1),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
set(get(get(pieH(3),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
set(get(get(pieH(5),'Annotation'),'LegendInformation'),'IconDisplayStyle','on')
I also tried passing the patched handles, as it says in the help, also with no effect:
legend([pieH(1:2:end)],{'Leg1','Leg2','Leg3'},'location','EastOutside');
Edit
I was using matlab handle graphics version 2, and it seems that this combinations does not work yet at new graphics version. Since it is a matlab bug and this topic led me to the discovering, I am closing it. But if someone, by chance, already had this issue and knows how to workaround please let me know.
here's a way to make it work:
X=[100 200 300];
h=pie(X);
legend(h(1:2:end), 'Small', 'Medium', 'Large','location','EastOutside');
I have drown several graphs thanks to "subplot" function on MatLab and it works well.
Nevertheless, I want all my graphs to have the same Y-scale so that I can compare them.
I used the "linkaxes" function and my all my graphs have the same scale but the problem is that some of my figures are "beheaded", lacking their upper part, or one of my figures is completely squeezed.
I don't get what happened. Could you please help me to solve the problem or tell me about another function that would be more appropriate in my case?
Here's part of my code:
for i=1:1:9
m=n(i);
fichier=sprintf('%d.txt',m);
M=load(fichier);
z=length(M(:,1));
x=M(1:z,1);
y=M(1:z,2);
a(i)=subplot(2,4,i)
contour3=plot(x,y)
linkaxes(a,'y')
end
linkaxes creates a permanent link between the scales of several axes, so that you can subsequently perform zoom operations (perhaps interactively) on one, and have the other automatically update.
If you need that functionality, then linkaxes is the right command (although you could possibly also look at linkprops).
However if all you need is to ensure that the y-axis limits of your axes are the same, it will probably be easier (and you will have more control) if you set them directly. You can retrieve the y-axis limits using ylim(axis_handle) and set them using ylim(axis_handle, [lower, upper]), or alternatively with get(axis_handle,'YLim') and set(axis_handle,'YLim',[lower,upper]). You might also look at the YLimMode property of the axis, which determines whether the axis limits are directly set or automatically resized.
In R2010b, I can reset the tick labels to auto thru figure editor,
but I'd like to reset them to default programmatically
I tried
set(gca,'XTickLabel','auto')
But it displays 'auto' at each tick... Any hint ?
You need to set XTickLabelMode to 'auto':
set(gca,'XTickLabelMode','auto')
Tick label modes are set to 'manual' when you specify tick labels. So, you need to turn it back to 'auto'.
OK, I finally found this way:
set(gca,'XTickLabel', num2str(get(gca,'XTick')'));
I read the ticks and transform them back to strings...
EDIT: note that this a workaround that happens to work if you don't zoom nor resize the figure, but which is not robust to zoom/resize because the XTickLabelMode remains 'manual' and thus the XTickLabel won't be updated when you zoom.
I added this answer because this is the first thing I found (and others might find too).
The reason why it is not the preferred way is more usefull than the answer itself, thus this edit.
The right solution to do it, is the one that I accepted.
I'm trying to change the background color of a single subplot in a MATLAB figure.
It's clearly feasible since the UI allows it, but I cannot find the function to automate it.
I've looked into whitebg, but it changes the color scheme of the whole figure, not just the current subplot.
(I'm using MATLAB Version 6.1 by the way)
You can use the set command.
set(subplot(2,2,1),'Color','Red')
That will give you a red background in the subplot location 2,2,1.
I know you mentioned that you are using MATLAB 6.1, but it bears mentioning that in the newer versions of MATLAB you can specify additional property-value pair arguments in the initial call to SUBPLOT, allowing for a more compact syntax. The following creates an axes with a red background in the top left corner of a 2-by-2 layout:
subplot(2,2,1,'Color','r');
I'm not certain in which version of MATLAB this syntax was introduced, since the release notes going back to Version 7 (R14) don't seem to mention it.
I've not used Matlab in several years, but I think it might well be the whitebg method called after the subplot declaration, similar to the way in which you would set a title.
subplot(3, 2, 4), hist(rand(50)), whitebg('y');