In [8]:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.sans-serif'] = [u'simHei'] #用来正常显示中文标签
mpl.rcParams['axes.unicode_minus'] = False #用来正常显示负号
%matplotlib inline
#https://www.cnblogs.com/zhizhan/p/5615947.html

In [9]:
np.logspace(-3,2,10)


Out[9]:
array([  1.00000000e-03,   3.59381366e-03,   1.29154967e-02,
         4.64158883e-02,   1.66810054e-01,   5.99484250e-01,
         2.15443469e+00,   7.74263683e+00,   2.78255940e+01,
         1.00000000e+02])

In [10]:
np.linspace(-3,2,10)


Out[10]:
array([-3.        , -2.44444444, -1.88888889, -1.33333333, -0.77777778,
       -0.22222222,  0.33333333,  0.88888889,  1.44444444,  2.        ])

In [11]:
labels='frogs','hogs','dogs','logs'
sizes=15,20,45,10
colors='yellowgreen','gold','lightskyblue','lightcoral'
explode=0,0.1,0,0
plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=50)
plt.axis('equal')
plt.show()



In [14]:
plt.colors


Out[14]:
<function matplotlib.pyplot.colors>

In [16]:
x = [1,2,3,4,5]
y = [2.3,3.4,1.2,6.6,7.0]

plt.figure(figsize=(12,6))

plt.subplot(231)
plt.plot(x,y)
plt.title("plot")

plt.subplot(232)
plt.scatter(x, y)
plt.title("scatter")

plt.subplot(233)
plt.pie(y)
plt.title("pie")

plt.subplot(234)
plt.bar(x, y)
plt.title("bar")

# 2D data
import numpy as np
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z    = Y**2 + X**2

plt.subplot(235)
plt.contour(X,Y,Z)
plt.colorbar()
plt.title("contour")

# read image
import matplotlib.image as mpimg
img=mpimg.imread('marvin.jpg')

plt.subplot(236)
plt.imshow(img)
plt.title("imshow")

plt.savefig("matplot_sample.jpg")


C:\Anaconda3\lib\site-packages\numpy\ma\core.py:6385: MaskedArrayFutureWarning: In the future the default for ma.maximum.reduce will be axis=0, not the current None, to match np.maximum.reduce. Explicitly pass 0 or None to silence this warning.
  return self.reduce(a)
C:\Anaconda3\lib\site-packages\numpy\ma\core.py:6385: MaskedArrayFutureWarning: In the future the default for ma.minimum.reduce will be axis=0, not the current None, to match np.minimum.reduce. Explicitly pass 0 or None to silence this warning.
  return self.reduce(a)

In [18]:
np.meshgrid(-5,5,1)


Out[18]:
[array([[[-5]]]), array([[[5]]]), array([[[1]]])]

In [20]:
np.arange(-5,5)


Out[20]:
array([-5, -4, -3, -2, -1,  0,  1,  2,  3,  4])

In [21]:
points=np.arange(-5,5,0.01) #生成1000个间隔相等的点
xs,ys=np.meshgrid(points,points)
ys
import matplotlib.pyplot as plt
z=np.sqrt(xs**2+ys**2)
z
plt.imshow(z,cmap=plt.cm.gray);plt.colorbar();plt.title('image plot of $\sqrt{x^2+y^2}$ for a grid of values')


Out[21]:
<matplotlib.text.Text at 0x19ab4c18>

In [22]:
x = [1,2,3,4]
y = [2,4,6,8]

In [24]:
plt.figure(figsize=(12,6))


Out[24]:
<matplotlib.figure.Figure at 0x60f9358>
<matplotlib.figure.Figure at 0x60f9358>

In [25]:
plt.subplot(231)
plt.plot(x,y)


Out[25]:
[<matplotlib.lines.Line2D at 0x60f94a8>]

In [26]:
plt.bar(x,y)


Out[26]:
<Container object of 4 artists>

In [27]:
plt.scatter(x,y)


Out[27]:
<matplotlib.collections.PathCollection at 0x168c6f60>

In [28]:
plt.pie(y)


Out[28]:
([<matplotlib.patches.Wedge at 0x16835518>,
  <matplotlib.patches.Wedge at 0x1683c1d0>,
  <matplotlib.patches.Wedge at 0x1683ce10>,
  <matplotlib.patches.Wedge at 0x16841a90>],
 [<matplotlib.text.Text at 0x16835d30>,
  <matplotlib.text.Text at 0x1683c9b0>,
  <matplotlib.text.Text at 0x16841630>,
  <matplotlib.text.Text at 0x168472b0>])

In [29]:
plt.pie([2,2,2,2])


Out[29]:
([<matplotlib.patches.Wedge at 0x19ba67b8>,
  <matplotlib.patches.Wedge at 0x19bab470>,
  <matplotlib.patches.Wedge at 0x19bb10f0>,
  <matplotlib.patches.Wedge at 0x19bb1d30>],
 [<matplotlib.text.Text at 0x19ba6fd0>,
  <matplotlib.text.Text at 0x19babc50>,
  <matplotlib.text.Text at 0x19bb18d0>,
  <matplotlib.text.Text at 0x19bb7550>])

In [45]:
points=np.arange(-2,3) #生成1000个间隔相等的点
points2 = np.arange(-6,4)
xs,ys=np.meshgrid(points,points)
ys
import matplotlib.pyplot as plt
z=xs**2+ys**2

In [46]:
points


Out[46]:
array([-2, -1,  0,  1,  2])

In [47]:
xs


Out[47]:
array([[-2, -1,  0,  1,  2],
       [-2, -1,  0,  1,  2],
       [-2, -1,  0,  1,  2],
       [-2, -1,  0,  1,  2],
       [-2, -1,  0,  1,  2]])

In [48]:
ys


Out[48]:
array([[-2, -2, -2, -2, -2],
       [-1, -1, -1, -1, -1],
       [ 0,  0,  0,  0,  0],
       [ 1,  1,  1,  1,  1],
       [ 2,  2,  2,  2,  2]])

In [49]:
z


Out[49]:
array([[8, 5, 4, 5, 8],
       [5, 2, 1, 2, 5],
       [4, 1, 0, 1, 4],
       [5, 2, 1, 2, 5],
       [8, 5, 4, 5, 8]], dtype=int32)

In [50]:
plt.imshow(z)


Out[50]:
<matplotlib.image.AxesImage at 0x19c10128>

In [51]:
plt.plot(z)


Out[51]:
[<matplotlib.lines.Line2D at 0x19c65c50>,
 <matplotlib.lines.Line2D at 0x19c65e10>,
 <matplotlib.lines.Line2D at 0x19c6b0f0>,
 <matplotlib.lines.Line2D at 0x19c6b2e8>,
 <matplotlib.lines.Line2D at 0x19c6b4e0>]

In [ ]: