How display a log space bar figure ?

2 次查看(过去 30 天)
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')

采纳的回答

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

更多回答(1 个)

Akira Agata
Akira Agata 2020-1-25
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

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by