How to draw line graph with same values in this bar graph?

3 次查看(过去 30 天)
x = [1 2 3 4 5 6 7];
temp_high = [149.1350 143.9020 19.1230 19.0350 11.8150 19.8610 11.6600];
w1 = 0.5;
bar(x,temp_high,w1,'FaceColor',[0 0 1])
temp_low =[29.8270 28.7804 3.8246 3.8070 2.3630 3.9722 2.3320];
w2 = .25;
hold on
bar(x,temp_low,w2,'FaceColor',[1 0 0])
hold off
grid on
ylabel('Cost Incurred')
legend({'Units of gas consumed','cost incurred'},'Location','northwest')
ax = gca;
ax.XTick = [1 2 3 4 5 6 7];
ax.XTickLabels = {'Adding item to chain','Purchasing item from list','Shipment of item','Receiving item','Checking balance in user account','Fetching of item status','Total item count calculation'};
ax.XTickLabelRotation = 45;

采纳的回答

VBBV
VBBV 2020-11-28
clear
x = [1 2 3 4 5 6 7];
temp_high = [149.1350 143.9020 19.1230 19.0350 11.8150 19.8610 11.6600];
w1 = 0.5;
bar(x,temp_high,w1,'FaceColor',[0 0 1])
temp_low =[29.8270 28.7804 3.8246 3.8070 2.3630 3.9722 2.3320];
w2 = .25;
hold on
bar(x,temp_low,w2,'FaceColor',[1 0 0])
hold on
plot(x,temp_high,'b-','linewidth',2)
hold on
plot(x,temp_low,'r-','linewidth',2)
grid on
ylabel('Cost Incurred')
legend('Units of gas consumed','cost incurred','Units of gas consumed','cost incurred','Location','northwest')
ax = gca;
ax.XTick = [1 2 3 4 5 6 7];
ax.XTickLabels = {'Adding item to chain','Purchasing item from list','Shipment of item','Receiving item','Checking balance in user account','Fetching of item status','Total item count calculation'};
xtickangle(45)
  3 个评论
VBBV
VBBV 2020-11-28
clear
x = [1 2 3 4 5 6 7];
temp_high = [149.1350 143.9020 19.1230 19.0350 11.8150 19.8610 11.6600];
w1 = 0.5;
temp_low =[29.8270 28.7804 3.8246 3.8070 2.3630 3.9722 2.3320];
w2 = .25;
plot(x,temp_high,'b-','linewidth',2)
hold on
plot(x,temp_low,'r-','linewidth',2)
grid on
ylabel('Cost Incurred')
legend('Units of gas consumed','cost incurred','Location','northwest')
ax = gca;
ax.XTick = [1 2 3 4 5 6 7];
ax.XTickLabels = {'Adding item to chain','Purchasing item from list','Shipment of item','Receiving item','Checking balance in user account','Fetching of item status','Total item count calculation'};
xtickangle(45)

请先登录,再进行评论。

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2020-11-28
编辑:Ameer Hamza 2020-11-28
Are you looking for something like this
x = [1 2 3 4 5 6 7];
temp_high = [149.1350 143.9020 19.1230 19.0350 11.8150 19.8610 11.6600];
w1 = 0.5;
bar(x,temp_high,w1,'FaceColor',[0 0 1])
hold on
plot(x,temp_high, 'LineWidth', 2)
temp_low =[29.8270 28.7804 3.8246 3.8070 2.3630 3.9722 2.3320];
w2 = .25;
bar(x,temp_low,w2,'FaceColor',[1 0 0])
plot(x,temp_low, 'LineWidth', 2)
hold off
grid on
ylabel('Cost Incurred')
legend({'Units of gas consumed','cost incurred'},'Location','northwest')
ax = gca;
ax.XTick = [1 2 3 4 5 6 7];
ax.XTickLabels = {'Adding item to chain','Purchasing item from list','Shipment of item','Receiving item','Checking balance in user account','Fetching of item status','Total item count calculation'};
ax.XTickLabelRotation = 45;
  1 个评论
soujanya duvvi
soujanya duvvi 2020-11-28
Yes i want only the line graph i dont want the bar plot in it. Can i just retain the line plot and remove the bar plot?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by