I would like to plot a bar chart like below in MATLAB. Any one know which function should I use? Many thanks in advance!
The bar is specified with range in x (some may be wider than others).
There is no line between two bars (red cross in the figure).
X axis is in log scale.
why don't you try to do it with the plot or semilogx function?
x = [0.1 0.18 0.18 0.32 0.32 0.56 0.56 1.0];
y = [30 30 25 25 110 110 80 80];
semilogx(x,y);
and if you want the x ticks like in your figure you can set them on the axis object:
ax = gca;
ax.XTick = unique(x);
ax.XTickLabel = unique(x);
Related
I have made a matrix containing 13 different vectors with ~300K+ rows. I have visualized the matrix by transposing it and using the imagesc function to see the distribution of colors. All vectors have been resampled, processed and normalized between 0 & 1 individually.
The imagesc plot gives me this result (fig 1):
But, when I use the axis functionality to add x & y limits, I get this:
How do I maintain the imagesc plot while being able to add custom ticks and labels to the X & y axis? The x axis represents time, while the y axis will get its own labels with sensor names.
You redefine limits from 0 to 30 on the x-axis while the initial xlimits goes up to 3e5. Same issue with the y-axis
Here's how to redefine the Y-axis to put sensor names:
C = [0 2 4 6 9 ; 8 10 12 44 14; 16 48 10 32 23];
image(C)
% Get axis handle
ax = gca;
% Set where ticks will be
ax.YTick = [1 2 3];
% Set TickLabels;
ax.YTickLabel = {'S1','S2','S3'};
Figure out the ax.YTick where you want the labels to appear.
If you want the x-axis to go from 0 to 30, divide the x component of all vectors by 1e4 before plotting. Alternatively, you can add the line:
ax.XTickLabel = ax.XTick/1e4;
I have a polar plot that has colored contours. I cannot figure out how to add my axis. The code is below:
close all
data1 = xlsread('C:\Users\Desktop\practice.xlsx','theta');
data2 = xlsread('C:\Users\Desktop\practice.xlsx','r');
data3 = xlsread('C:\Users\Desktop\practice.xlsx'','z');
t = data1(1,:);
r = data2(:,1);
z = data3(:,:);
figure(1)
title('Displacement')
polarcont(r,t,z)
myColorMap = colormap;
myColorMap(1,:) = [1 1 1];
colormap(myColorMap);
colorbar;
caxis([0 25]);
beta = 0.9;
brighten(beta)
From here I cannot figure out how to plot my axes. For instance at theta=0, I would like [100], etc. Whenever I try what usually works,
thetaticks([0 15 30 45 60 75 90 105 120 135 150 165 180 195 210 225 240 255 270 285 300 315 330 345])
rticks([100 200 300])
rticklabels({'100 eV','200 eV','300 eV'})
ax = gca;
ax.ThetaAxis.TickLabelInterpreter = 'latex';
ax.ThetaTickLabel = {'[100]','','','[101]','','','[001]','','','[$\overline{1}$01]','','','[$\overline{1}$00]','','','[$\overline{1}$0$\overline{1}$]','','','[00$\overline{1}$]','','','[10$\overline{1}$]','','','[$\overline{1}$0$\overline{1}$]'};
I just get riddled with errors involving trying to use polar axes on a cartesian chart. I can plot circles below which can give me the different r mag, but seems kind of a silly way to do it to me: (below)
plotting_circle(0,0,100);
plotting_circle(0,0,200)
plotting_circle(0,0,300)
plotting_circle(0,0,400)
axis equal
axis off
I am coding to make a trendline on my scatter plot.
data=[];
for k=1:100
int=0;
for t=1:100
if k_star_90(k,t)~=0
int=int+k_star_90(k,t);
end
if k_star_90(k,t)==0 && int~=0
data=[data int];
int=0;
end
end
end
intervals = linspace(0, 1, 100);
h1 = histc(data, intervals);
scatter(intervals, h1, 'r');
set(gca,'xscale','log')
set(gca,'yscale','log')
picture of plot result
This is in log-log scale. On this plot, I want to draw y=ax+b(1st order) trendline. I am not sure how to do it.
I will really appreciate your help
I'm not sure I understood your intention correctly, but if you need a trend line you may do something like this
intervals = [0.01 0.02 0.2 0.1 0.3 0.5 0.03 0.4 0.15 0.2 0.2 0.25 1 0.9 0.8 0.8 0.7];
h1 = [70 40 4 20 2 3 60 10 50 40 10 20 1 2 3 1 2] ;
coeffs = polyfit(intervals, h1, 1);
xFitting = 0:0.01:1;
yFitted = polyval(coeffs, xFitting);
scatter(intervals, h1, 'r');
set(gca,'xscale','log');
set(gca,'yscale','log');
grid on;
hold on;
plot(xFitting, yFitted, 'b', 'LineWidth', 2);
hold off;
ylim([1 80]);
xlabel('intervals');
ylabel('h1');
Here is your trend in Log scale:
Og course it does not look like a first order trend. To depict it as a line you need to go back to a normal plot:
I want to describe surface flatness of a plane with interp2 function.
Spatial sampling points are as below.
width=[0 500];
length=[0 100 200 300 400 500 600 700 800 900 1000];
and flatness are as below, at width 0 and 500, respectively.
a = [1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1]; % flatness at width 0
b = [-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1]; % flatness at width 500
With these values, the surface shape will be like following figure.
I wanted to change this figure into following figure with interp2 function.
Below is my code.
widthq=[0 100 200 300 400 500];
flatness=[a' b'];
flatnessq=interp2(width,length,flatness,widthq,length);
But, not working with one error, 'The input data has inconsistent size.'
Can anyone explain this error and give a way how to interpolate my data with interp2 function?
The first three inputs need all to be of the same size
[W, L] = meshgrid(width, length);
The last two arguments need also to be of same size
[Wq, Lq] = meshgrid(widthq, length);
Then it should work
flatnessq=interp2(W,L,flatness,Wq,Lq);
My data is sparse therefore when I plot my graph I get the following result
As you can see the first x axis tick starts at 500(s), but most of my data is around 30(s). Can I change the scaling of the x axis?
How about this?
X = [1 3 6 10 25 30 235 678 1248];
Y = [0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.8 0.9];
plot(X,Y,'-b.')
figure
semilogx(X,Y,'-b.')
I see the following output:
If you want to display data from 0 to 30s only you can either plot only those like this:
idcs=Xdata <30; %# find indices where X is less than 30s
plot(Xdata(idcs),Ydata(idcs),'b'); %#plot only these data.
or you can just express XLimits on the figure.
plot(Xdata,Ydata,'b'); %# plot everything
set(gca,XLim,[0 30]); %# limit display on X axis