赞
踩
直接看注释吧,知行合一!
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 21 10:36:28 2017
罗干,同济大学图书馆
我爱婷婷和臭臭
@author: user
"""
#导入模块
from matplotlib import pyplot as plt
import numpy as np
#定义两个矩阵
A1=np.array([0,0])
B1=np.array(([2,0],[0,2]))
#以 A1为均值,B1为协方差矩阵,生成正态分布的随机数
C1=np.random.multivariate_normal(A1,B1,10)
C2=np.random.multivariate_normal(A1+0.2,B1+0.2,10)
#画布的大小为长8cm高6cm
plt.figure(figsize=(8,6))
#画图吧,s表示点点的大小,c就是color嘛,marker就是点点的形状哦o,x,*><^,都可以啦
#alpha,点点的亮度,label,标签啦
plt.scatter(C1[:,0],C1[:,1],s=30,c='red',marker='o',alpha=0.5,label='C1')
plt.scatter(C2[:,0],C2[:,1],s=30,c='blue',marker='x',alpha=0.5,label='C2')
#下面三行代码很简单啦
plt.title('basic scatter plot ')
plt.xlabel('variables x')
plt.ylabel('variables y')
plt.legend(loc='upper right')#这个必须有,没有你试试看
plt.show()#这个可以没有
import matplotlib.pyplot as plt
x_coords = [0.13, 0.22, 0.39, 0.59, 0.68, 0.74, 0.93]
y_coords = [0.75, 0.34, 0.44, 0.52, 0.80, 0.25, 0.55]
fig = plt.figure(figsize=(8,5))
plt.scatter(x_coords, y_coords, marker='s', s=50)
for x, y in zip(x_coords, y_coords):
plt.annotate(
'(%s, %s)' %(x, y),
xy=(x, y),
xytext=(0, -10),
textcoords='offset points',
ha='center',
va='top')
plt.xlim([0,1])
plt.ylim([0,1])
plt.show()
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8,6))
# Generating a Gaussion dataset:
# creating random vectors from the multivariate normal distribution
# given mean and covariance
mu_vec1 = np.array([0,0])
cov_mat1 = np.array([[1,0],[0,1]])
X = np.random.multivariate_normal(mu_vec1, cov_mat1, 500)
R = X**2
R_sum = R.sum(axis=1)
plt.scatter(X[:, 0], X[:, 1],
color='gray',
marker='o',
s=32. * R_sum,
edgecolor='black',
alpha=0.5)
plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。