Generate Matlab Plot Code from Figure Editor - matlab

I'm plotting a spectrogram in Matlab and have been editing the axis properties, colormap, and a few other things manually by hand in the Figures editor ("Edit > Colormap or Axis Properties...").
Is there a way to generate/view the code that is creating the plots from the Figure Editor? I could/should dig around some more to see what the calls are to show/fix the color bar and the color map, but it would be really nice to just see the code exactly how I've edited it through the Figure editor. Is this possible?

In the editing menu you can show the code-changes simply by right-clicking into the figure and choosing "Show-M-Code"

Related

How to show the complete legend in the plot window of Dymola?

I am trying to plot some of my results in Dymola, but when I plot a few curves in one graph, the legend can't show completely, is there any setup I could use to let the legend show completely?
You can select from various legend styles in the plot window setup.
In your case Right would be the choice.

Colorbar not appearing in (surface) plot - LaTeX interpreter issue

As the title states, the colorbar in surface plots does not appear when the default interpreter is set to 'latex'. This occurs in MATLAB 2012b and 2013a and on two different machines.
Precisely, the colorbar object is created, can be clicked when editing the plot, can be edited using the interactive colorbar editor but is not visible at all.
It does not appear when saved as a figure and reopened, saved as a PNG, exported in .eps format or saved as a .pdf.
After searching around, I found the following post from 2011, concerning MATLAB 7:
http://mathforum.org/kb/message.jspa?messageID=7518470
Specifically, the interpreter appears to be at fault, when it is set to 'latex', the colorbar will not display. When set to the default, it does.
Here is the smallest demonstrating example.
set(0,'defaulttextinterpreter','none');
figure;
surf(peaks(100)); colorbar
set(0,'defaulttextinterpreter','latex');
figure
surf(peaks(100)); colorbar
The two figures are identical except that the colorbar is visible only in the first figure.
I use a lot of special characters and sub/superscripts in my plots so in startup.m I set the default interpreter to 'latex'. I could surround all calls to colorbar with:
set(0,'defaulttextinterpreter','none');
colorbar;
set(0,'defaulttextinterpreter','latex');
But this is probably the least elegant solution possible. Can anyone shed some light on this issue which appears to be extant for over 5 years and multiple editions of MATLAB?
This behaviour is gone in Matlab R2014b, which uses an entirely new graphics engine, hg2. The plots look different (most of the time in a better way), but instead of old, documented bugs, there are now new, undocumented bugs...
Earlier versions of Matlab support somewhat experimental stages of hg2. You can enable these by running Matlab with the switch "-hgVersion 2". You can do this, for example, by editing the Desktop shortcut to point to something like "C:\Program Files\MATLAB\R2013b\bin\matlab.exe" -hgVersion 2.
Unfortunately, with the new graphics engine being the default in Matlab2014b, the old bugs are less likely to be fixed in the future. I wish I could help you in a better way, but the workaround you posted seems like a good solution, especially if you wrap it in a function called robust_colorbar or so.
I can reproduce the problem on my system (R2010b, Windows Vista 32 bits) . It seems to be solved by changing the 'Renderer' property of the figure from the default 'OpenGL' to either 'painters' or 'zbuffer'. So, you can either change the renderer when creating the figure:
set(0, 'defaulttextinterpreter', 'latex');
figure('Renderer', 'zbuffer') %// this line changed
surf(peaks(100)); colorbar
or change the default renderer to be used for all figures (so you don't need to change it in every figure):
set(0, 'DefaultFigureRenderer', 'zbuffer'); %// this line added
set(0, 'defaulttextinterpreter', 'latex');
figure
surf(peaks(100)); colorbar
Using a renderer other than 'OpenGL' may affect features such as transparency or drawing speed. Here's some information about pros and cons of each renderer.

Change color of line plotted with Tools>Basic fitting

I have several different data series that i would like to do a shape-preserving curve fit on.
I have the points plotted but when i go into Tools>Basic fitting>Shape-preserving interpolant the curve gets a random(?) colour and when i go to the next series the fit disapears.
How do make the fits stay for each data serie and how do change its colour afterwards using the toolbox in the plot window. If there is no easy solution is it possible with script, what to write?
This is what one data series looks like
%950
Wloss_950=950/(PWM1_1250CoreLoss+PWM4_1250CoreLoss)*(885.7312-632.7188)+632.7188;
Wloss_950=[Wloss_950;950/(PWM2_2000CoreLoss+PWM4_2000CoreLoss)*(405.8198-281.4403)+281.4403];
Wloss_950=[Wloss_950;950/(PWM3_2500CoreLoss+PWM5_2500CoreLoss)*(107-24.5466)+24.5466];
Wloss_950=[Wloss_950;950/(PWM3_4000CoreLoss)*24.5466];
Wloss_950=[Wloss_950;950/(PWM3_5000CoreLoss)*20.5796];
plot(speed, Wloss_950,'+','color', 'red')
In the figure window go to Tools -> Edit Plot then double tap on the line and editor window should open, in which you will be able to change colour, width, etc.

Fix position of legend in MATLAB

How do I fix the position of a legend in a MATLAB figure?
I'm currently building a GUI, intended for public use, and when figures inside the GUI are produced I do not want the user to be able to move the legend by click-and-drag. Anyone?
You have to remove the buttonDownFcn from the legend.
snippet:
line(rand(1,3),rand(1,3))
l=legend('location','ne')
set(l,'ButtonDownFcn',[])

MATLAB Graphing plots with axes

I have been trying to Create a program with the GUI in MATLAB. When I try to plot information with AXES I can not figure out how to do it. I know about the function plot, but I need to be able to re-size and move the plot around in the figure so I can make room for the input uicontrol. I am not sure what to do. Please help.
There are a couple of different ways to tackle this problem. But the way I always choose to do so, is:
hold on:
plot(...), xlim([xmin xmax), ylim(ymin ymax])
This should set your bounds on the axis.
I don't have Matlab at hand right now, but try the following:
To set size of the plot axes inside the figure window use
set(gca,'Position',[left bottom width height])
see Mathworks' site on axes properties