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

3 views (last 30 days)
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;

Accepted Answer

VBBV
VBBV on 28 Nov 2020
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 Comments
VBBV
VBBV on 28 Nov 2020
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)

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 28 Nov 2020
Edited: Ameer Hamza on 28 Nov 2020
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 Comment
soujanya duvvi
soujanya duvvi on 28 Nov 2020
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!