scatter 基本用法 python matplotlib
生活随笔
收集整理的這篇文章主要介紹了
scatter 基本用法 python matplotlib
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
直接看注釋吧,知行合一!
# -*- 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 pltx_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 pltfig = 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()轉載自斗大的熊貓
總結
以上是生活随笔為你收集整理的scatter 基本用法 python matplotlib的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于BP神经网络的大牛的论述
- 下一篇: 验证码的产生 python