DOC PREVIEW
TAMU CSCE 110 - Plotting Graphs
Type Lecture Note
Pages 2

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSCE 110 1nd EditionLecture 13Outline of Last Lecture:I. Continuation of SimulationsII. SetsA. IntroductionB. More properties of setsOutline of Current Lecture:I. Plotting GraphsA. Basic Set-UpB. Legends/LabelsC. Saving Current Lecture:I. Plotting Graphs: We can transform a list of points and values into a visual representation. A. Let's start with the most basic set-up. Eventually, we will add on different things one at a time. First, seen in line 1, we will need to use an import, just like we did in order to be able to use random numbers. 1 >>> import matplotlib.pyplot2 >>> matplotlib.pyplot.plot (range(0,10), [9,4,5,1,2,5,7,12,2,3])3 >>> matplotlib.pyplot.show()In line 2, we give the list of points we want plotted. We do this by giving a specified domain (range(0,10)) and range (the list of ten elements). Line 3 contains the command to actually display the graph. The name of the graph is matplotlib.pyplot - we have to type this whole nameout before we do anything with it (we can follow with .plot and given points, or with .show() to actually display the graph). However, even though we will always have to begin with matplotlib.pyplot and type out the name of the graph for every command, we can rename it to something shorter. We can do this by adding an "as [insert new name here]". Our new program will look like this:1 >>> import matplotlib.pyplot as plot2 >>> plot.plot (range(0,10), [9,4,5,1,2,5,7,12,2,3])3 >>> plot.show()Now whenever we do something with the graph, we only have to type out a much shorter name. We can also add multiple curves to the graph. We would just have more than one of line 2, with possibly different points given, changing what the x-values correspond to. These notes represent a detailed interpretation of the professor’s lecture. GradeBuddy is best used as a supplement to your own notes, not as a substitute.B. Adding Legends/LabelsIt is nice to actually show what is being represented on the graph. 1 >>> import matplotlib.pyplot as plot2 >>> plot.plot (range(10,30,2), [9,4,5,2,3,5,7,12,2,3], label='curve1', marker='o')3 >>> plot.plot (range(10,30,2), [10,13,1,7,3,19,7,20,0,4], label='curve2', marker='^')4 >>> plot.xlabel('x axis')5 >>> plot.ylabel('y axis')6 >>> plot.title('a simple plot')7 >>> plot.legend()8 >>> plot.grid()9 >>> plot.show()Notice how this time we have two separate curves, shown in lines 2 and 3. Having multiple curves is made easier by having a legend and labels on the graph in order to tell what is what. Inlines 2 and 3, we added two things inside the parentheses. The first is a label: we simply give the curve a name to refer to in the legend of the graph. The second is a marker: this will give each point a specific shape to mark the point. A 'o' signifies a circle and a '^' signifies a triangle. In lines 4 and 5, we are simply labeling the x and y axes on the graph. We do this by writing the name of the graph followed by .xlabel('[the name]') or .ylabel('[the name]'). In line 6, we give the graph a header, and in line 7, we allow the legend of the graph to be displayed. In line 8, we add a grid to the background of the graph, in order to see the points more easily. For all of theselines, aside from line 1, we have the name of the graph followed by some function. C. Saving the GraphThere are multiple ways to save a graph. We can save it as different types of documents as well. 1 >>> import matplotlib.pyplot as plot2 >>> plot.plot (range(10,30,2), [9,4,5,2,3,5,7,12,2,3], label='curve1', marker='o')3 >>> plot.plot (range(10,30,2), [10,13,1,7,3,19,7,20,0,4], label='curve2', marker='^')4 >>> plot.xlabel('x axis')5 >>> plot.ylabel('y axis')6 >>> plot.title('a simple plot')7 >>> plot.legend()8 >>> plot.grid()9 >>> plot.savefig('sample-plot.pdf')10 >>> plot.savefig('sample-plot.jpeg')11 >>> plot.show()In lines 9 and 10, we save the file as two different types. We write the name of the graph, followed by .savefig('[name of the graph].[type of


View Full Document

TAMU CSCE 110 - Plotting Graphs

Type: Lecture Note
Pages: 2
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download Plotting Graphs
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Plotting Graphs and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Plotting Graphs 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?