Let's recall how to code a linspace array and perform some computations. You will see in this Module how to create various graphs and pie charts to display your data in meaningful ways. Let's get started!
Review the code to the right, which shows an example of how to complete the two steps below. Run the code cell to see the output.
Step 1. Create a linspace array called "x" that goes from 1 to 40 with 20 buckets. Then, print the array x.
Step 2. Calculate a new array called "y" that is calculated as 2x+7.2 Then, print the array y.
Coding Assistance: Click this link if you need help solving this problem.
Pyplot is a Matplotlib module that provides simple functions for plotting and graphing. See the simple example on the right.
In this example, the three bottom lines of code use pyplot to create and display the graph.
More information on these functions and other pyplot functions can be found on the next slide!
Note that the first array x provides the x-axis coordinates, and the second array y provides the y-axis coordinates!
In this video you will learn learn a few basic commands to get starting plotting data right away! (Feel free to use the adjust the trinket file above to code along with the video). We will also work to customize the plots; thus allowing you to change the colors of your points and lines, the line styles (dashed, dotted, etc...), and even what markers will be displayed at each of your (x,y) points on your graph.
Step 1.
Run This Code
Step 2.
Modify the existing arrays and run it again to make it more straightforward
Let's explore changing the line styles, colors, and markers being used on our graphs. (Hint: Be sure to refer back to the information above summarizing the most useful colors, marker types, and line styles).
Use the shorthand plt.plot command to change the color, marker and line types to be:
green,
square markers,
dash-dot line style
Now that you've learned how to code a regular line graphs by typing in the first and second arrays, let's try using an equation and plot the results.
Step 1: Create an array "first_array" going from 100 to 4 with 50 buckets.
Step 2: Create the
output_array = (first_array)3 + 2.75
Step 3: Use the plt.plot command create the graph with the following graph formatting:
cyan,
hexagon markers,
dashed line style