![mojr1000](/avatars/23434.jpg)
mojr1000
06.04.2020 •
Computers and Technology
Implement a function with signature barGraph(w, h, data) which creates and returns a cs1graphics.Canvas instance that has width w and height h and which visualizes the given data as a bar graph. The data will be a nonempty list of positive integers. (You do not need to error-check the parameters.) Your visualization must have rectanglar bars with equal width that collectively use 80% of the width of the canvas (leaving 10% padding on left and right) and the bars should be vertically aligned at their bottom edge such that the maximum value in the data results in a bar that uses 80% of the height of the canvas (leaving 10% padding at top and bottom). As an example, the call barGraph (400, 300, [5, 8, 2, 7]) should produce the following image: from cs1graphics import * def barGraph(w, h, data): pass
Solved
Show answers
More tips
- F Food and Cooking How to Set Up Ventrilo - The Ultimate Guide...
- L Leisure and Entertainment How to Make a Crab Trap in Just a Few Minutes...
- H Health and Medicine How Much Does Abortion Cost? Expert Answers and Insights...
- S Sport How to Build Arm Muscles? Effective Exercises and Tips...
- H Health and Medicine When can it be said that a person has a normal pulse?...
- A Art and Culture When Will Eurovision 2011 Take Place?...
- S Style and Beauty How to Choose the Perfect Hair Straightener?...
- F Family and Home Why Having Pets at Home is Good for Your Health...
- H Health and Medicine How to perform artificial respiration?...
- H Health and Medicine 10 Tips for Avoiding Vitamin Deficiency...
Answers on questions: Computers and Technology
- C Chemistry Why is using only clean glassware important?...
- A Advanced Placement (AP) Ihave a lot of make up work to do anything will...
- B Biology An ameba is a single-celled, heterotrophic organism. in order to meet its energy needs, it relies directly on the interaction of which cell structures?...
- M Mathematics Suppose you toss a coin 100 times and get 76 heads and 24 tails. based on these results, what is the probability that the next flip results in a head?...
Ответ:
def barGraph(w, h, data):
# creating Canvas
paper = Canvas(w, h)
# defining variables
largest = max(data) # largest element in data
length = len(data) # length of data list
barWidth = 0.8 * w / length # length of each bar of the histogram
maxBarHeight = 0.8 * h # maximum height of each bar of the histogram
minBarHeight = maxBarHeight / largest # minimum height of each bar
# Starting points
x = 0.1 * w
y = 0.9 * h
# looping through the list
for i in data:
currBarHeight = minBarHeight * i # current bar height
x1 = x + barWidth
y1 = y - currBarHeight
# creating the rectangle, and adding it to the bar graph
bar = Polygon( Point(x,y), Point(x,y1), Point(x1,y1), Point(x1,y) )
bar.setFillColor('grey')
paper.add(bar)
x = x1
# returning the canvas
return paper
Ответ:
70 m^2.
Step-by-step explanation:
Area of the triangle = 1/2 * base * height.
Counting the squares on the coordinate plane:
Base = 7, height = 5
Each square = 2 meters
So the area = 1/2 * 14 * 10
= 70m