I want to plot a bar chart in Matlab with (1) log-scale for x-axis and (2)bars in same width. But with the code below, the width of the bars are different. Can any one help? Many thanks!
xdata = [0.01 0.018 0.032 0.056 0.1 0.18 0.32 0.56 1 1.8 3.2 5.6 10];
ydata = [1.3 1.6 1.5 1.2 1.0 3.5 0.6 3.1 1.6 1.9 1.7 0.3 0.4];
bar(xdata,ydata);
set(gca,'XScale','log');
Plot Multiple Lines Create a vector of x-coordinates and two vectors of y-coordinates. Plot two lines by passing comma-separated x-y pairs to loglog . Alternatively, you can create the same plot with one x-y pair by specifying y as a matrix: loglog(x,[y1;y2]) .
Plot a bar chart using the left y-axis. Plot a line chart using the right y-axis. Assign the bar series object and the chart line object to variables. days = 0:5:35; conc = [515 420 370 250 135 120 60 20]; temp = [29 23 27 25 20 23 23 17]; yyaxis left b = bar(days,temp); yyaxis right p = plot(days,conc);
bar( y ) creates a bar graph with one bar for each element in y . To plot a single series of bars, specify y as a vector of length m. The bars are positioned from 1 to m along the x-axis. To plot multiple series of bars, specify y as a matrix with one column for each series.
Instead of plotting xdata
on a log scale, plot the log of xdata
on a linear scale. Then modify labels to reflect the linear value (not the used log value).
xdata = [0.01 0.018 0.032 0.056 0.1 0.18 0.32 0.56 1 1.8 3.2 5.6 10];
ydata = [1.3 1.6 1.5 1.2 1.0 3.5 0.6 3.1 1.6 1.9 1.7 0.3 0.4];
bar(log10(xdata),ydata);
set(gca,'Xtick',-3:1); %// adjust manually; values in log scale
set(gca,'Xticklabel',10.^get(gca,'Xtick')); %// use labels with linear values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With