Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: Python Problem 5.14. Plotting graphs A graph is a collection of lines and points in the plane such that each line connects two points.

Language: Python

image text in transcribedimage text in transcribed

Problem 5.14. Plotting graphs A graph is a collection of lines and points in the plane such that each line connects two points. In this exercise we will create functions for plotting graphs on a set of points. a) Make a function plot_line (pl,p2) that takes two points as input argu- ments and plots the line between them. The two input arguments should be lists or tuples specifying - and y-coordinates, i.e. pl =(x1, y1). Demonstrate that the function works by plotting a vertical and a horizontal line. D 3 D4 D D Figure 5.1: Examples of complete graphs from Problem 5.14 b). The left shows the graph on the corners of the unit square, the right is the graph for eight equally spaced points on a circle. b) A complete graph is a graph such that any two points has a line that connects them. Make a function that takes a list of points and plots the complete graph on those points. To verify that the function works, first choose the four corners of the square (0,0), (1.0), (0,1),(1, 1)) and then the points (1,0),(a, a),(0,1),(-a, a),(-1,0),(-a, -a), (0.-1),(0, -a), with a = V2/2. The resulting complete graphs should look like the ones in Figure 5.1. Hint: Modify the plot_line function from 5.14 a) so that it only calls plot() but not show(). The complete graph can then be drawn by looping over the points and calling plot_line for each pair, and finally calling show() after the loop. Filename: graph1.py

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions