-
Created by Unknown User (jonakaa), last modified on 12.06.2019
You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 10
Next »
Simple plots
import numpy as np
import matplotlib.pyplot as plt
# Evenly sampled time from 0s to 10s at 200ms intervals
t = np.arange(0.0, 10.0, 0.2)
# Plotting t at x-axis and sin(t) at y-axis
plt.plot(t, np.sin(t))
# Naming the title and both axis
plt.title('Sinus function')
plt.ylabel('sin(t)')
plt.xlabel('t [s]')
# Need to call the show() function at the end to display my figure
plt.show()
![](/wiki/download/attachments/146605768/Simple%20plot.png?version=1&modificationDate=1560334640000&api=v2)
import numpy as np
import matplotlib.pyplot as plt
# Evenly sampled time at 200ms intervals
t = np.arange(0.0, 5.0, 0.2)
# plot() can plot several lines in the same figure. To seperate the different lines
# from eachother, we may change the line style and format strings.
# See the plot() documentation for a complete list of line styles and format strings.
# The following lines have red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', label='Linear line')
plt.plot(t, t**2, color='blue', linestyle='none', marker='s', label='Second degree polynom')
plt.plot(t, t**3, 'g^', label='Third degree polynom')
# To describe our plot even more detailed we can draw the labels we previously gave our lines using legend.
plt.legend(loc='upper left')
# The function axis() sets the axis sizes, and takes the argument [xmin, xmax, ymin, ymax]
plt.axis([0, 5, 0, 100])
plt.title('Mulitple polynoms')
plt.show()
![](/wiki/download/attachments/146605768/Several%20simple%20plots%20in%20same%20figure.png?version=2&modificationDate=1560337523000&api=v2)