Computer graphics program to draw a bar graph using a graphics library

0
467

Computer graphics program in Python and C++

Python

import matplotlib.pyplot as plt 
  
# creating the dataset
# data = {'Monday':20, 'Tuesday':15, 'Wednesday':30, 
#         'Thursday':35, 'Friday' : 0, 'Saturday' : 5, 'Sunday' : 20}
keys = list(map(str, input("Enter keys: ").split()))
values = list(map(str, input("Enter values: ").split()))
courses = list(keys)
values = list(values)
 
fig = plt.figure(figsize = (10, 5))
 # creating the bar plot
plt.bar(courses, values, color ='blue', 
       width = 0.4)
 plt.show()

from graphics import *
win = GraphWin("Experiment 2-2", 600, 600)
 
#title
label = Text(Point(290, 7), 'Concentric Circles')
label.draw(win)
 
#center
center = Point(300, 300)
 
#circle1
c1 = Circle(center, 70)
c1.draw(win)
 
#circle2
c2 = Circle(center, 40)
c2.draw(win)
 
win.getMouse()
win.close()
computer graphics

C++

#include<bits/stdc++.h>
#include<graphics.h>
#include<conio.h>
using namespace std;
void chart(vector<int> a){
    line(100, 50, 100, 350); 
    line(100, 350, 400, 350);
    int left = 150;
    for(auto i: a){
        bar(left, 350 - i, left + 30, 350);
        left += 40;
    } 
}
int main(){
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");
    int n;
    cout << "Enter the number of items: ";
    cin >> n;
    vector<int> a(n);
    cout << "Enter the Frequencies: ";
    for(auto &i: a) cin >> i;
    chart(a);
    getch();
    closegraph();
    return 0;
}
computer graphics

LEAVE A REPLY