Change markers in dynamic plots - matlab

What I have:
hold on
for i =1:length(tspan)
var{i} = Tv(:,i);
str{i} = ['t = ',num2str(tspan(i)), ' s'];
plot(z,var{i},'DisplayName',str{i});
end
legend('-DynamicLegend');
This works perfectly (thanks to this), but it prints out all blue lines.
I tried to set up a colormap (the default) and use it like this, but the output was the same
plot(z,var{i},'DisplayName',str{i},'Color', colormap(i,:));
And I would also like to see different markers for each plot. How is it possible to change them?
EDIT
Thanks to ironzionlion I fixed the colors. How can I do the same with markers?

According to the post that you mention, you have to define that you will need i different colours in your plot. This can be done by using colors = hsv(i)
Your plot sentence will then be: plot(z,var{i},'DisplayName',str{i},'Color', colors(i,:));
Update
I am not aware of the existance of "markermap". You could fix the problem just by define upfront the different markers that you want (quick and dirty solution): mrk={'o','+','*','.'};
Then you will plot by selecting each time the corresponding marker:
plot(z,var{i},'DisplayName',str{i},'Color', cmap(i,:),'Marker', mrk{i});

Related

How does Holoviews know which colours to assign to each scatterplot in an overlay?

In the bokeh Holoviews gallery, there is an example called 'Scatter economic'.
http://holoviews.org/gallery/demos/bokeh/scatter_economic.html#bokeh-gallery-scatter-economic
In this plot, notice how one of the options for Scatter is (color=Cycle('Category20')). The last line of the plot is gdp_unem_scatter.overlay('Country').
My question is: How does Holoviews know to connect each Scatter to a particular color in Cycle('Category20')? Is this just a property of Cycle()? Is there some way that the Overlay interacts with the Scatter and with the Cycle automatically?
A slightly related confusion is that if I use the .opts method instead of the cell magic as in the example, it still works. For example, if I use the .opts method with this cycle color on the Scatter (i.e., second to the last line in the above example), and then do an .overlay('Country'), somehow Holoviews knows to assign each Scatter to a particular color based on the Country.
I want to make sure that I am properly plotting what I intend to.
Thank you!
It is now possible to map categories in an NdOverlay (as is used in the example above) by using a so called dim expression and then define an expression to do the mapping:
dim_expr = hv.dim('category').categorize({'A': 'red', 'B': 'green', 'C': 'blue'})
overlay = hv.NdOverlay({chr(65+i): hv.Scatter(np.random.rand(10, 2)) for i in range(3)}, 'category')
overlay.opts(hv.opts.Scatter(color=dim_expr))
In this example we created a dim expression which points to the 'category' dimension and then maps each category ('A', 'B' and 'C') to a color ('red', 'green', 'blue'). We then just assign that to the color option.
How does Holoviews know to connect each Scatter to a particular color in Cycle('Category20')? Is this just a property of Cycle()? Is there some way that the Overlay interacts with the Scatter and with the Cycle automatically?
You are correct that Cycle and Overlay are designed to interact in this way automatically. More explicitly, each color in the Cycle gets assigned to a 'layer' of the overlay until the cycle runs out of colors and it loops.
For example, if I use the .opts method with this cycle color on the Scatter (i.e., second to the last line in the above example), and then do an .overlay('Country'), somehow Holoviews knows to assign each Scatter to a particular color based on the Country.
This is because your call to opts customizes the options on the elements of the data structure before you call the overlay method on (this data structure is a HoloMap). The options set there are propagated to the Scatter elements in the HoloMap which will now have the chosen Cycle specified. This means that when these elements get put into an overlay, HoloViews can look up the Cycle appropriately and apply it correctly to the overlay.
Hope that makes sense!

Matlab border around figure

In attached image the output looks boring to me. Is it possible to have the subplots enclosed in a border?
Note: This question is not specific to publishing only but in general, say for exported images also.
Thanks
Postscript: I actually need this:
You can add a box like in here
making your code:
close all
figure()
padd=0.04
axes('Position',[padd padd 1-padd*2 1-padd*2],'xtick',[],'ytick',[],'box','on','handlevisibility','off')
subplot(1,2,1)
imagesc(magic(2))
subplot(1,2,2)
imagesc(magic(3))
This yields
And you can change the padd to be bigger or smaller
I obtained this just by plotting lines of different thickness 1.
The text was added with Inkscape though.
If I understand correctly what you want to do, you can obtain borders inside a figure using uipanels http://www.mathworks.com/help/matlab/ref/uipanel.html like this:
Code is:
u=uipanel('Title','MainPanel')
u1=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 1','Position',[0,0,0.5,1])
u2=uipanel('Parent',u,'BorderType','line','HighlightColor','k','Title','Subpanel 2','Position',[0.5,0,0.5,1])
axes1=axes('Parent',u1)
imagesc(magic(2))
axes2=axes('Parent',u2)
imagesc(magic(3))
Of course you can change border widths, colors, titles and such

Alter tick labels to a '10^ - style' appearance

Though there are quite a lot of answered questions to that kind of issue, I wasn’t able to find a proper solution for my exact problem. Anyway.
I try to format my tick lables like shown in the following example:
I already found out that the ‘sprintf’ command is offering a possibility to alter the tick format. The closest I came to what I want is the 'e-notation' triggered by the following command:
set(ax,'YTickLabel',sprintf('%2.0e|',yticks))
However, I’d like my labels to appear just as shown in the example picture. Is there a simple way to do that?
Thank you very much in advance,
Joe
You could use Latex formatting and sprintfc to produce what you want. (You might not need sprintfc at all actually but that's a nice way of creating a cell array of strings with numbers in a single line.):
set(ax,'YTickLabels',sprintfc('10^{%i}',yticks)
In a general example (here with x-axis formatted):
clear
clc
close all
x = 0:100000;
y = log(x);
figure
semilogx(x,y)
xt = get(gca,'XTick');
set(gca,'XTickLabels',sprintfc('10^{%i}',0:numel(xt)-1))
outputs the following:
Am I missing something? Why not use semilogy?
x = -3:0;
y = 10.^x;
semilogy(x, y);
set(gca, 'YMinorGrid', 'on')

removing units from plot

I try to remove the Matlab-given units from this plot but I don't find a way:
figure(1)
hold on
set(gcf,'PaperUnits','centimeters',...
'PaperSize',[15 9],...
'PaperPosition',[0 0 15 9]);
pzmap(LB); sgrid; grid on; axis equal;
title('');
xlabel('\sigma [rad/s]')
ylabel('\omega [rad/s]')
hold off
After that commands the xlabel looks like this: \sigma [rad/s] (seconds^-1). The seconds comes with pzmap. How can I remove them?
I found, some strange behavour:
If generate code by the figure plot manager I get this:
% Create xlabel
xlabel('\sigma [rad/s] (seconds^{-1})','Units','pixels');
Why???
Now I get it - without pzmap/pzplot
pol = pole(sys)
figure(1)
plot(real(pol(:)),imag(pol(:)),'x')
title('');
xlabel('\sigma [rad/s]');
ylabel('\omega [rad/s]');
sgrid
pzmap is a high-level convenience function, but it's not the best choice for this (it's also stored in a folder of obsolete functions in R2013a, so it may get marked for official removal in the future). Instead, let's create an example plot using pzplot directly instead of pzmap. This is still a plot function that does a lot under the hood, but it returns a handle, h, to the plot:
sys = rss(3,2,2);
h = pzplot(sys);
sgrid;
axis equal;
We can via the options of a pzplot with getoptions:
p = getoptions(h)
To set the labels and units as you desire, you might try this, using setoptions:
p.Title.String = '';
p.XLabel.String = '\sigma';
p.YLabel.String = '\omega';
setoptions(h,p);
I believe that the units of 'seconds-1' that the plot displays is equivalent to the 'rad/s' that you want to specify. I know that the two look is very different (I prefer being specific about radians myself), but that's a disadvantage of using such a plot function that tries to do everything for you. If you wanted to remove the default string or add another option, you'd likely have to do some low level hacking. An easier way around, might be to use the "Generate Code..." command ("Generate M-File..." in older versions") under the "File" menu in the figure's toolbar and edit the plot labels there (there's also a programmatic option for this on the File Exchange). Or you could output to postscript and edit that.
Alternatively, you can use pzoptions to create a list of options to pass to pzplot or pzmap (undocumented in the latter case):
p = pzoptions;
p.Title.String = '';
p.XLabel.String = '\sigma';
p.YLabel.String = '\omega';
sys = rss(3,2,2);
pzplot(sys,p);
sgrid;
axis equal;
You'll see that that for some reason the text size is much smaller in this case. pzplot and pzmap must set the font size to 10 themselves. You could easily do this.
Fore more on customizing this and related Control toolbox plots, see this article.
After intense low-level digging, there is actually a pretty simple way to override the default behavior.
p = pzplot(sys);
p.AxesGrid.XUnits = 'rad/s';
p.AxesGrid.YUnits = 'rad/s';
Changes appear to take effect immediately. I have even tried setting the value to nothing, i.e.
p.AxesGrid.XUnits = '';
and it effectively removes the annoying parenthesis with the units. Technically, matlab creates a custom-class element they store under the name AxesGrid in the resppack.mpzplot class instance, with some standard LTI-behavior. You can probably work around some stuff by "injecting" a script with the same name as one of the standard library functions, so that it will be called instead, and change things in there, but this is the closest I have come to removing those annoying units in a few lines.
As a side info, the AxesGrid object is initialized in
...\controllib\graphics\#resppack\#pzplot\initialize.m
should you want to check it out.

Change label of data tips on bode nichols diagram

When we plot a bode/nichols locus, the name of workspace variable is used
tmp=ss(1,1,1,0);
nichols(tmp);
will use 'tmp' as label.
When using more complex data, matlab is using 'untitled1','untitled2',...
tmp={ss(1,1,1,0) , ss(1.2,1,1,0)};
nichols(tmp{:});
How can I change this label programmatically?
Ideally, I'd like a solution working with Matlab 6.5.1, but I'm also interested in solutions restricted to newer versions.
You can modify the labels programmatically via their graphics handles. It looks like the values you want to change are the DisplayName property of some of the children of the current axis. So in your first example, I can change the display name like this:
ch = get(gca,'Children');
set(ch(1),'DisplayName','Fred');
In general, I'm not sure how to predict which children of the current axis are the ones you need to change. For the second example you give, the two curves appear to be the second and third children when I run your code.