Is there a way to make matlab gridlines bold? - matlab

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

Related

How to draw rectangle around tiled object in a MATLAB plot?

I created a tiledlayout(4,3)-object and I want to emphasize the 8th tile by a surrounding line or changing the backgroundcolor (not of the graph itself, but just the greyspace behind the graph, labels, axes etc.).
I could not find anything that changes the backgroundcolor of just one tile, so I tried to draw a rectangle around the tile and color it.
I executed the code below and expected to get a red line around the OuterPosition- or the TightInset-position, but nothing happened. The code created the tiles without any error-codes and there was no red rectangle around the 8th tile.
Can anyone tell me how to color the background of a tile or get a rectangle around it?
Thank you very much!
ax = nexttile(8)
lines_around_tile = get(ax, 'OuterPosition'); %'TightInset')
rectangle('Position', lines_around_tile, 'EdgeColor', 'r', 'LineWidth',10)
I got this result.
Result
To draw a rectangle, run the code and in matlab figure (with all the tiles) go to view -> Plot Edit Toolbar. It generates a toolbar where you can find lines, rectangles, circles...
Then insert your rectangle, right click on it, Property Inspector. In this window you can change the facecolor, linecolor, linewidth...

Matrix Semilogx linestyle and linewidth change

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 :)

add semi-transparency to 2d histogram

I am trying to make a plot like this one:
I want a 2D histogram with bar color proportional to the height and semi-transparent bars.
I tried to put together the examples provided here
x = randn(100, 2);
figure
hist3(x, [20 20]);
colormap(hot) % heat map
grid on
view(3);
%bar color
set(get(gca,'child'),'FaceColor','interp','CDataMode','auto');
%semitransparency
set(gcf,'renderer','opengl');
An example of the result is this:
The semi-transparency is absent.
I do not know if it is a problem of my Matlab version (R2014a) or if ---more probably--- I am messing up something. Maybe the axis handles?
Next
Outside this question: I would also like to add a transparent surface interpolating the histogram values (I got also some problems with this). I think I saw something like this on SO recently, but I cannot find it anymore. Does anyone have some hits?
You didn't actually change the surface transparency in your example. All you did was change renderers. Here's the extra line you would need:
set(get(gca,'child'),'FaceAlpha',0.8);
A value of 1 would be opaque, 0 invisible.
You may also want to change the edge line transparency too:
set(get(gca,'child'),'EdgeAlpha',0.2);

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!