Clear Filters
Clear Filters

How display a log space bar figure ?

1 view (last 30 days)
Hi I have plotted a bar figure but I want that the y axis log space.
Please can you rectify my code.
clear all
clc
maxV_l = [0.015232 0.020273 0.0069196 0.012027 0.010313 0.012567 0.014836 0.015071 0.016182 0.018388 0.013878];
maxV_m = [12.911 15.205 6.6378 10.659 9.3996 11.026 12.564 12.685 13.418 14.511 12.082];
maxV_h = [ 166.73 138.81 167.74 148.64 146.5 155.99 149.72 162.55 172.41 166.32 154.67];
% Create a vertical bar chart using the bar function
figure (1)
bar(1:11, [maxV_l' maxV_m' maxV_h'],1)
% Set the axis limits
set(gca,'xticklabel',{'PZT-5A','PZT-5H','PZT-7A','PZT-4','PZT-8','APC-8740','APC-850','SONOX-P504','SONOX-P508','PIC-151','PIC-255'});
% Add title and axis labels
xlabel('Material')
ylabel('|Peak Voltage| [V/g]')
% Add a legend
legend('Rl=100\Omega', 'Rl=100k\Omega', 'Rl=10M\Omega')

Accepted Answer

Stephan
Stephan on 25 Jan 2020
% Set y-axis to log scale
set(gca, 'YScale', 'log')

More Answers (1)

Akira Agata
Akira Agata on 25 Jan 2020
Please set YScale property of the axes to 'log'.
The following is an example.
maxV_l = [0.015232 0.020273 0.0069196 0.012027 0.010313 0.012567 0.014836 0.015071 0.016182 0.018388 0.013878];
maxV_m = [12.911 15.205 6.6378 10.659 9.3996 11.026 12.564 12.685 13.418 14.511 12.082];
maxV_h = [ 166.73 138.81 167.74 148.64 146.5 155.99 149.72 162.55 172.41 166.32 154.67];
% Create a vertical bar chart using the bar function
figure
bar([maxV_l' maxV_m' maxV_h'],1)
ax = gca;
ax.XTickLabel =...
{'PZT-5A','PZT-5H','PZT-7A','PZT-4','PZT-8','APC-8740','APC-850','SONOX-P504','SONOX-P508','PIC-151','PIC-255'};
ax.XTickLabelRotation = 45;
ax.YScale = 'log';
ax.YLim(2) = 1e4; % To make additional space for a legend
% Add title and axis labels
xlabel('Material','FontSize',12)
ylabel('|Peak Voltage| [V/g]','FontSize',12)
% Add a legend
legend('Rl=100\Omega', 'Rl=100k\Omega', 'Rl=10M\Omega')
bar.png

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!