Question: 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

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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!