<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Plotting with Matplotlib
Step1:  Plotting Datapoints
Let's start by plotting four points
Step2:  Three functions were called during the generation of this plot
Step3:  Let's say we wanted a line drawn between the points. Matplotlib has got us covered with the plot function.
Step4:  Matplotlib has gone ahead and interpolated a line between consecutive points. However it would be useful to still show the original points. This can be achieved using the marker keyword argument.
Step5:  There are lots of different marker styles available. A list of them can be found here.
Maplotlib has also given us some nice limits for our plot, however let's imaginge we needed the plot to show the origin.
Step6:  This plot looks pretty good. Too good. Let's add in error bars using the errorbar function.
Step7:  To specify x-errors use the xerr keyword.
Function Plotting
Step8:  A whole bunch of stuff just happened. Let's take a minute to go through it
Step9:  That looks much smoother. Now let's plot multiple figures in a single plot.
Step10:  This is as simple as making two calls to plot. However with two different things on the plot it's a good idea to label them.
Step11:  And that's the general gist of generating plots.
Semilog and Log-Log Plots
Sometimes you want to have either the x-axis, y-axis or both as a log scale.
Step12:  It's hard to see what's happening to see what's happening with this power function on a normal scale. Let's clean it up using a semi-log plot.
Step13:  If you wanted the log scale on the x-axis you would use the semilogx function.
For log-log plots use the loglog function.
Step14:  One thing to note is that when using a logarithmic scale, linspace isn't the best function to use because the distribution of sample points becomes skewed visually.
Step15:  This can be improved by using the logspace function which takes as its first three arguments a starting power, ending power and the number of points to sample.
Step16:  Saving Plots to a File
To including plots in reports, it's useful to be able to save them.
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plt
import numpy as np
# For presentation purposes only.
%matplotlib inline
Explanation: Plotting with Matplotlib
End of explanation
x = [1, 2, 3, 5]    # List of x coordinates.
y = [4, 3, 6, 2]    # List of y coordinates.
y_error = [0.1, 0.5, .2, 0.25] # Errors associated with the y readings.
plt.scatter(x, y)
plt.show()       # Displays the plot.
plt.clf()        # Clears the plot.
Explanation: Plotting Datapoints
Let's start by plotting four points: 
* (1, 4)
* (2, 3)
* (3, 6)
* (5, 2)
End of explanation
plt.scatter(x, y)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Basic Scatterplot")
plt.grid()
plt.show()
plt.clf()
Explanation: Three functions were called during the generation of this plot:
* scatter: takes a list of x-coordinates and a list of y-coordinates and generates a scatterplot. 
* show: makes Python display the generated plot.
* clf: clears the generated figure.
This plot is missing a couple of important features though:
* Axes labels.
* A title.
* A background grid.
Let's fix that.
End of explanation
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Plot with Interpolated Lines")
plt.grid()
plt.show()
plt.clf()
Explanation: Let's say we wanted a line drawn between the points. Matplotlib has got us covered with the plot function.
End of explanation
plt.plot(x, y, marker="D") # D is for diamond
plt.xlabel("x")
plt.ylabel("y")
plt.title("Plot with Interpolated Lines and Points Displayed")
plt.grid()
plt.show()
plt.clf()
Explanation: Matplotlib has gone ahead and interpolated a line between consecutive points. However it would be useful to still show the original points. This can be achieved using the marker keyword argument.
End of explanation
plt.plot(x, y, marker="D")
plt.xlim([0, 5.2])    # Displays the x-axis from 0 to 4
plt.ylim([0, 6.4])    # Displays the y-axis from 0 to 7
plt.xlabel("x")
plt.ylabel("y")
plt.title("Plot Showing Origin")
plt.grid()
plt.show()
plt.clf()
Explanation: There are lots of different marker styles available. A list of them can be found here.
Maplotlib has also given us some nice limits for our plot, however let's imaginge we needed the plot to show the origin.
End of explanation
plt.plot(x, y, marker="x") # x is for x
plt.errorbar(x, y, yerr=y_error) # Adding in error bars.
plt.xlabel("x")
plt.ylabel("y")
plt.title("Realistic Plot")
plt.grid()
plt.show()
plt.clf()
Explanation: This plot looks pretty good. Too good. Let's add in error bars using the errorbar function.
End of explanation
x = np.linspace(-np.pi, np.pi, 10, endpoint=True)
y = np.sin(x)
plt.plot(x, y, marker=".")
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.title("Sine Function")
plt.grid()
plt.show()
plt.clf()
Explanation: To specify x-errors use the xerr keyword.
Function Plotting
End of explanation
x = np.linspace(-np.pi, np.pi, 100, endpoint=True) # Switch from 10 to 100 points.
y = np.sin(x)
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.title("Sine Function")
plt.grid()
plt.show()
plt.clf()
Explanation: A whole bunch of stuff just happened. Let's take a minute to go through it:
* np.pi: The numpy library has a value called pi, which conveniently stores the value of pi.
* np.linspace: This function generates a list of 10 points between -pi and pi.
* np.sin: sin function provided by the numpy library.
An important thing to wrap your head around is that plotting in Python is all about points. To plot a function you evaluate the function at many points and then plot those points. The plot above isn't particularly smooth. This can be improved by sampling more points.
End of explanation
x = np.linspace(-np.pi, np.pi, 100, True)
plt.plot(x, np.sin(x))
plt.plot(x, np.cos(x))
plt.xlabel("x")
plt.ylabel("y")
plt.title("Sine and Cosine Function")
plt.grid()
plt.show()
plt.clf()
Explanation: That looks much smoother. Now let's plot multiple figures in a single plot.
End of explanation
x = np.linspace(-np.pi, np.pi, 100, True)
plt.plot(x, np.sin(x), label="Sin(x)") # label associates a name with the plot.
plt.plot(x, np.cos(x), label="Cos(x)")
plt.xlabel("x")
plt.ylabel("y")
plt.title("Sine and Cosine Function")
plt.legend(loc='upper left')    # Display the legend in the upper right.
plt.grid()
plt.show()
plt.clf()
Explanation: This is as simple as making two calls to plot. However with two different things on the plot it's a good idea to label them.
End of explanation
x = np.linspace(-100, 10, 100, True)
plt.plot(x, 10**x)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Power Function")
plt.grid()
plt.show()
Explanation: And that's the general gist of generating plots.
Semilog and Log-Log Plots
Sometimes you want to have either the x-axis, y-axis or both as a log scale.
End of explanation
plt.semilogy(x, 10**x) # Semi-Log Plot
plt.xlabel("x")
plt.ylabel("y")
plt.title("Exponential Function - Semi-Log Plot")
plt.grid()
plt.show()
Explanation: It's hard to see what's happening to see what's happening with this power function on a normal scale. Let's clean it up using a semi-log plot.
End of explanation
x = np.linspace(1, 10000, 50, True)
plt.loglog(x, x) # Log-log Plot
plt.xlabel("x")
plt.ylabel("y")
plt.title("Log-Log Plot")
plt.grid()
plt.show()
Explanation: If you wanted the log scale on the x-axis you would use the semilogx function.
For log-log plots use the loglog function.
End of explanation
x = np.linspace(1, 10**3, 50, True)
plt.loglog(x, x, marker="x", linestyle='None')
plt.xlabel("x")
plt.ylabel("y")
plt.title("Skewed Log-Log")
plt.grid()
plt.show()
Explanation: One thing to note is that when using a logarithmic scale, linspace isn't the best function to use because the distribution of sample points becomes skewed visually.
End of explanation
x = np.logspace(1, 3, 50, endpoint=True, base=10)
plt.loglog(x, x, marker="x", linestyle='None')
plt.xlabel("x")
plt.ylabel("y")
plt.title("Clean Log-Log")
plt.grid()
plt.show()
Explanation: This can be improved by using the logspace function which takes as its first three arguments a starting power, ending power and the number of points to sample.
End of explanation
x = np.linspace(0, 10, 50)
plt.xlabel("x")
plt.ylabel("y")
plt.title("A Line")
plt.grid()
plt.plot(x, x)
plt.savefig("Line.pdf") # Save the plot.
plt.clf()
Explanation: Saving Plots to a File
To including plots in reports, it's useful to be able to save them.
End of explanation
<END_TASK>