Matrix Semilogx linestyle and linewidth change - matlab

I need some help making some changes in the way my plot is plotted with this code.
First of all, I need dark colours. I want my the lines to start from black and slowly go to dark red/purple. Scaling from black to dark red/purple smoothly.
The other thing I need is on how to get other variations in my linestyle. I stole the linestyle code from somewhere and it is kinda useful, but I need more than the 4 variations given.
I also wanna add another line, with semilogx again and add it on the legend. How can I achieve that without messing with the previous legend? If I just add the line and put an extra line on the legend, it gives me the wrong color. (if I just use hold on and add an ,'', in the legend it gets a parula color and not the actual color)
fig = semilogx(SMPSFIN(1,5:75),z);
numLines = length(fig);
cmap = colormap(parula(numLines));
style = {'-','--',':','-.'};
for i = 1:numLines
fig(i).Color = cmap(i,:);
set(fig(i),'Linewidth',i*sqrt(1.5*i)*0.1);
set(fig(i),'linestyle',style{1+int8(mod(i,4))});
end
Thanks a lot for your time :)

Related

Is there a way to make matlab gridlines bold?

I know that I can set the color of gridlines using:
pax = gca;
pax.GridColor = 'black';
But the gridlines are still a faint grey. I would like to make them darker. Is there a way to make the gridlines bold?
Note I do not want to make the gridlines thicker, I just want to make them darker that the faint grey that seems to be the automatic when using black
I am using polar plots and when I print them, the grids are almost too faint to see.
You need to modify the GridAlpha property as well so that the grid lines are actually opaque. The default value is 0.15 so even though they are black they appear gray since they are transparent. You'll want to use a GridAlpha value of 1 .
pax.GridAlpha = 1

How to set the background colour of different legends in plotyy (Matlab)?

If I execute following code:
figure
t=0:.1:10;
dummy=plotyy(t,sin(t),t,2*cos(t));
set(dummy(1),'ylim',[-1 1]);
set(dummy(2),'ylim',2*[-1 1]);
axes(dummy(1)); xlabel('xlabel'); ylabel('ylabel');
axes(dummy(2)); ylabel('ylabel2');
dummy(1).YTick=[-1:.5:1];
dummy(2).YTick=[-2:1:2];
legend(dummy(1),'Legend1','Location','NorthWest')
legend(dummy(2),'Legend2','Location','NorthEast')
I obtain following figure:
It seems that the default colour of the right-hand legend is grey instead of white. Which command do I need to enter in order to make it white?
It is a good question, I can only assume that MATLAB try's to match some colors for readability or something like that. If you want to know it exactly, maybe MATLAB provides a legend.m-file within the program directory which you could open to have a look at the specific source.
In case you only want to know how to work around it to make both legends white, use this code:
l1 = legend(...);
l2 = legend(...);
set(l2, 'color' 'white');

Overlapping graphs in matlab

I am drawing several graphs in the same plot in matlab by using the command, hold on.
My problem is that I am drawing points with big markersize on top of some of the graphs, and I would like theses points to have some specific color. Only what happens is that some of them will take some color and some others take another color, my guess is that the colors of my points get mixed with the colors of the graphs on top of which i put them. Is there a mean to ask matlap to overwrite whatever is under my points so that they get the color I assign to them?
Example:
x= 0:1:10;
plot(x,x,'r',x,-x,'b','linewidth',2)
hold on
plot(5,-5,'.',10,10,'.','MarkerColor',[0,0.5,0],'Markersize',24)
hold on
plot(5,5,'.',10,-10,'.','MarkerFaceColor',[0,0.75,0],'MarkerSize', 24)
Imagine that the curves are much more complicated than theses simple lines so no way to start having fun cutting them each time I want to represent a point...
Now my problem is that I would like that the points 5,-5 and 10,10 to have the same color. Namely 0 0.5 0 dark green. but their color get mixed depending on which line they lie.
If I specify their color as '.g' I don't get this problem, but the problem is that I got too many points to get covered by the few number of colors that are labeled by letters (eg 'r' 'b' 'k' etc..).
Thankfully
Note that 'MarkerColor' doesn't exist, so I suppose it's a type and you meant 'MarkerFaceColor', just like in the other plot.
Then, hold on once is enough, you don't need to repeat it every time you want overlap another plot.
Finally, I suggest you simply use 'Color' instead of MarkerFaceColor. This should display your dots with the wanted color.
x= 0:1:10;
plot(x,x,'r',x,-x,'b','linewidth',2)
hold on
plot(5,-5,'.',10,10,'.','Color',[0,0.5,0],'Markersize',24)
plot(5,5,'.',10,-10,'.','Color',[0,0.75,0],'MarkerSize', 24)

Matlab: How to change the scaling of the legend on a wind rose plot

This may be a very simple problem but I would greatly appreciate your help. I have created a direction/intensity plot using the wind_rose function in Matlab, however, I would like to change the scaling of the legend. The plot currently produces a legend that has 12 colors that go up in 10 cm blocks, for example blue = 0-0.1, light blue = 0.1-0.2, green = 0.2-0.3 etc. I would like there to be far less colors and the scaling to be more like blue = 0-0.5, light blue = 0.5-1.0 etc. This is the code I use to plot the wind rose:
h = wind_rose(M,D,'dtype','meteo','n',12,'lablegend','Hm0 (metres)','ci', 0:10:60,'quad',[4])
Am I able to add a simple code that will scale the legend how I want it to be?
Figured it out:
'di', 0:0.5:3
Very simple really oops. I am now looking to remove white boxes that appear around text on the figure, any ideas?

Large matlab plot doesnt display properly when using colours

I have a large amount of data which I have plotted on a bar chart. The default is that the bars are all blue with no spaces. However when I try to add colours white lines appear on the solid blocks of colour. Why is this and is there a way to get rid of them?
n=3000
mydata=2-abs(randn(n,1));
x=zeros(n,1);
x(1:2*n/10)=1;
x(2*n/10+1:n/2)=2;
x(n/2 +1:6*n/10)=3;
x(6*n/10 +1:8*n /10)=4;
x(8*n/10 :n)=5;
data=[x,mydata];
data=sortrows(data,[1,2])
bar=bar(data(:,2));
bar_child=get(bar,'Children');
set(bar_child,'CData',data(:,1));
set(gca,'ytick',[])
set(bar_child, 'EdgeColor', 'none')
You can see the difference clearly if you try running it without the last 4 lines
bar_child=get(bar,'Children');
set(bar_child,'CData',data(:,1));
set(gca,'ytick',[])
set(bar_child, 'EdgeColor', 'none')
You're right - when you run the above without the last four lines, all bars are blue and you can't see any vertical white lines separating in the plot. However, if you zoom in, you can start to see the white lines. So they are there in other plot, just not as noticeable.
I'm not sure why this is happening. More vertical white lines appear as I resize the multi-colour plot.
A workaround is as follows. Since the default bar width is 0.8, change this to 1.0 so that there is no separation between bars
bar=bar(data(:,2),'BarWidth',1);
and re-run all lines of code. When I did this, the results looked fine (no vertical white lines).
Try this and see what happens!