17 KiB
17 KiB
In [ ]:
import matplotlib.pyplot as pltIn [ ]:
%matplotlib inlineIn [ ]:
plt.plot([1,2,3,6,4,2,3,4])In [ ]:
plt.plot([3.3, 4.4, 4.5, 6.5], [3., 5., 6., 7.])In [ ]:
import numpy as np
x = np.linspace(0., 10., 50)
y = np.sin(x)
plt.plot(x, y)In [ ]:
plt.plot(x, y, marker='o', color='green', linewidth=2)In [ ]:
plt.plot(x, y, marker='o', color='green', linewidth=0)In [ ]:
plt.plot(x, y, 'go') # means green and circlesIn [ ]:
# The following code reads in the file and removes bad values
import numpy as np
date, temperature = np.loadtxt('data/munich_temperatures_average_with_bad_data.txt', unpack=True)
keep = np.abs(temperature) < 90
date = date[keep]
temperature = temperature[keep]In [ ]:
# your solution hereIn [ ]:
# your solution hereIn [ ]:
x = np.random.random(100)
y = np.random.random(100)
plt.scatter(x, y)In [ ]:
v = np.random.uniform(0., 10., 100)
h = plt.hist(v,bins=[0,2,4,6,8,10],density=True) # we do h= to capture the output of the function, but we don't use it (here)In [ ]:
array = np.random.random((64, 64))
plt.imshow(array)In [ ]:
plt.imshow(array, cmap=plt.cm.gist_heat)In [ ]:
x = np.arange(-2.0, 2.0, 0.005)
y = np.arange(-2.0, 2.0, 0.005)
xx, yy = np.meshgrid(x, y)
zz = np.exp(-xx**2 - yy**2)*(xx-yy)**2
plt.axes().set_aspect('equal') # equal aspect ratio
contour_set = plt.contour(xx, yy, zz) # returns a set of contour lines for plt.clabel
plt.clabel(contour_set) # creates labels with gaps in the contoursIn [ ]:
# For example:
x = [1,2,3]
y = [1,2]
a, b = np.meshgrid(x, y)In [ ]:
print(np.shape(a), np.shape(b))
print(a)
print(b)In [ ]:
# at coordinate (0|1), we have (note: the first index determines y, the second x)
print(x[0], y[1], a[1][0], b[1][0])In [ ]:
x=np.arange(-10,10,0.1)
y=np.arange(-10,10,0.1)
xx,yy=np.meshgrid(x,y) # define meshgrid of all coordinates
# (can also work out radii etc)
kx =-yy
ky = xx
plt.streamplot(x,y,kx,ky,color='k')In [ ]:
x = np.random.random(100)
y = np.random.random(100)
plt.scatter(x, y)
plt.xlabel('x values')
plt.ylabel('y values')
plt.xlim(0., 1.)
plt.ylim(0., 1.)In [ ]:
x = np.random.random(100)
y = np.random.random(100)
plt.scatter(x, y)
plt.xlabel('x values')
plt.ylabel('y values')
plt.xlim(0., 1.)
plt.ylim(0., 1.)
plt.savefig('my_plot.png')In [ ]:
# your solution hereIn [ ]:
# your solution here