亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

正在回答

2 回答

#散點圖?scatter
fig?=?plt.figure()
#?fig.add_subplot(3,3,1)
ax?=?fig.add_subplot(3,3,1)
n?=?128
X?=?np.random.normal(0,1,n)
Y?=?np.random.normal(0,1,n)
T?=?np.arctan2(Y,X)
#?plt.axes([0.025,0.025,0.95,0.95])
#畫散點的?c是顏色,alpha是透明度
ax.scatter(X,Y,s=75,c=T,alpha=0.5)
#x和y的范圍limit
plt.xlim(-1.5,1.5),plt.xticks([])
plt.ylim(-1.5,1.5),plt.yticks([])
plt.axis
plt.title("scatter")
plt.xlabel("x")
plt.ylabel("y")
#plt.show()

#柱狀圖
fig.add_subplot(332)
n?=10
X?=?np.arange(n)
Y1?=?(1-X?/?float(n))?*?np.random.uniform(0.5,1.0,n)
Y2?=?(1-X?/float(n))?*?np.random.uniform(0.5,1.0,n)
plt.bar(X,+Y1,?facecolor?=?'#9999ff',?edgecolor?=?'white')
plt.bar(X,-Y2,?facecolor?=?'#9999ff',?edgecolor?=?'white')

for?x,y?in?zip(X,Y1):
????plt.text(x+0.4,y+0.05,'%.2f'?%?y,?ha?=?'center',?va=?'bottom')

for?x,y?in?zip(X,Y2):
????plt.text(x+0.4,-y-0.05,'%.2f'?%?y,?ha='center',?va?='top')



#餅圖
fig.add_subplot(333)
n?=20
Z?=?np.ones(n)
Z[-1]?=2
plt.pie(Z,explode=Z*?.05,colors=['%f'?%?(i?/?float(n))?for?i?in?range(n)],
????????labels=['%.2f'?%?(i/?float(n))?for?i?in?range(n)])
plt.gca().set_aspect('equal')
plt.xticks([]),?plt.yticks([])



#極坐標?polar?=?True
fig.add_subplot(334,polar?=?True)
n?=20
theta?=?np.arange(0.0,?2?*?np.pi,?2?*?np.pi?/n)
radii?=?10?*?np.random.rand(n)
#?plt.plot(theta,radii)
plt.polar(theta,radii)

#熱圖?heatmap
fig.add_subplot(335)
from?matplotlib?import??cm
data?=?np.random.rand(3,3)
cmap?=?cm.Blues
map?=?plt.imshow(data,interpolation='nearest',?cmap=cmap,?aspect="auto",?vmin=0,vmax=1)


#3D圖
from??mpl_toolkits.mplot3d?import?Axes3D
ax?=?fig.add_subplot(336,projection='3d')
ax.scatter(1,1,3,s=100)

#hot?map?熱例圖
fig.add_subplot(313)
def?f(x,y):
????return?(1-x?/?2+x?**?5?+?y?**3)?*?np.exp(-x?**2?-?y**2)
n=256
x?=?np.linspace(-3,3,n)
y?=?np.linspace(-3,3,n)
X,Y?=?np.meshgrid(x,y)
plt.contourf(X,Y,f(X,Y),8,alpha?=.75,?cmap=plt.cm.hot)

#保存圖片
plt.savefig("./data/fig.png")
plt.show()


1 回復 有任何疑惑可以回復我~
#1

慕移動7205362

謝謝!
2021-01-07 回復 有任何疑惑可以回復我~

import numpy as np

from numpy.linalg import *

import matplotlib.pyplot as plt

def main():

? ? '''

? ? x=np.linspace(-np.pi,np.pi,256,endpoint=True)

? ? c,s=np.cos(x),np.sin(x)

? ? plt.figure(1)

? ? plt.plot(x,c,color="purple",linewidth=1.0,linestyle="-",label="COS",alpha=0.5)

? ? plt.plot(x,s,"r",linewidth=0.5,label="SIN")

? ? plt.title("cos & sin")

? ? ax=plt.gca()

? ? ax.spines["right"].set_color("none")

? ? ax.spines["top"].set_color("none")

? ? ax.spines["left"].set_position(("data",0))

? ? ax.spines["bottom"].set_position(("data",0))

? ? ax.xaxis.set_ticks_position("bottom")

? ? ax.yaxis.set_ticks_position("left")

? ? plt.xticks([-np.pi,-np.pi/2,0,np.pi/2,np.pi],

? ? ? ? ? ? ? ?[r'$-\pi$',r'$-\pi/2$',r'$0$',r'$+\pi/2$',r'$+\pi$'])

? ? plt.yticks(np.linspace(-1,1,5,endpoint=True))

? ? for label in ax.get_xticklabels()+ax.get_yticklabels():

? ? ? ? label.set_fontsize(16)

? ? ? ? label.set_bbox(dict(facecolor="yellow",edgecolor="blue",alpha=0.2))

? ? plt.legend(loc="upper left")

? ? plt.grid()

? ? #plt.axis([-1,1,-0.5,1])

? ? plt.fill_between(x,np.abs(x)<0.5,c,c>0.5,color="blue",alpha=0.5)

? ? t=1

? ? plt.plot([t,t],[0,np.cos(t)],"y",linewidth=1,linestyle="--")

? ? plt.annotate("cos(1)",xy=(t,np.cos(1)),xycoords="data",xytext=(+10,+30),

? ? ? ? ? ? ? ? ?textcoords="offset points",arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.2"))

? ? plt.show()

? ? '''

? ? fig=plt.figure()

? ? ax=fig.add_subplot(331)

? ? n=128

? ? X=np.random.normal(0,1,n)

? ? Y=np.random.normal(0,1,n)

? ? T=np.arctan2(Y,X)

? ? #plt.axes([0.025,0.025,0.95,0.95])

? ? ax.scatter(X,Y,s=75,c=T,alpha=0.5)

? ? plt.xlim(-1.5,1.5),plt.xticks([])

? ? plt.ylim(-1.5,1.5),plt.yticks([])

? ? plt.axis

? ? plt.title("scatter")

? ? plt.xlabel("x")

? ? plt.ylabel("y")

? ??

? ? fig.add_subplot(332)

? ? n=10

? ? X=np.arange(n)

? ? Y1=(1-X/float(n))*np.random.uniform(0.5,1.0,n)

? ? Y2=(1-X/float(n))*np.random.uniform(0.5,1.0,n)

? ? plt.bar(X,+Y1,facecolor="red",edgecolor="white")

? ? plt.bar(X,-Y2,facecolor="green",edgecolor="white")

? ? for x,y in zip(X,Y1):

? ? ? ? plt.text(x+0.4,y+0.05,'%.2f'%y,ha="center",va="bottom")

? ? ? ? plt.text(x+0.4,-(y+0.05),'%.2f'%y,ha="center",va="top")

? ? ? ??

? ? fig.add_subplot(333)

? ? n=20

? ? Z=np.ones(n)

? ? Z[-1]*=2

? ? plt.pie(Z,explode=Z*.05,colors=['%f'%(i/float(n)) for i in range(n)],

? ? ? ? ? ? labels=['.2%f'%(i/float(n)) for i in range(n)])

? ? plt.gca().set_aspect('equal')

? ? plt.xticks([]),plt.yticks([])

? ??

? ? fig.add_subplot(334,polar=True)

? ? n=20

? ? theta=np.arange(0.0,2*np.pi,2*np.pi/n)

? ? radii=10*np.random.rand(n)

? ? plt.plot(theta,radii)

? ??

? ? fig.add_subplot(335)

? ? from matplotlib import cm

? ? data=np.random.rand(3,3)

? ? cmap=cm.Blues

? ? map=plt.imshow(data,interpolation='nearest',cmap=cmap,aspect='auto',vmin=0,vmax=1)

? ??

? ? from mpl_toolkits.mplot3d import Axes3D

? ? fig.add_subplot(336,projection="3d")

? ? plt.scatter(1,1,3)

? ??

? ? fig.add_subplot(313)

? ? def f(x,y):

? ? ? ? return (1-x/2+x**5+y**3)*np.exp(-x**2,-y**2)

? ? n=256

? ? x=np.linspace(-3,3,n)

? ? y=np.linspace(-3,3,n)

? ? X,Y=np.meshgrid(x,y)

? ? plt.contourf(X,Y,f(X,Y),8,alpha=0.75,cmap=plt.cm.hot)

? ? ? ??

? ? plt.show

? ??

? ??

if __name__=='__main__':

? ? main()

? ??


1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

有木有代碼呀

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號