Python科学绘图实例附代码Python绘图精简实例附代码
1.引⾃知乎:
还有源码,我加了详细的注释,应该不难理解
import matplotlib.pyplot as plt
import numpy as np
# 空⼼框
boxcell_x = np.concatenate([np.arange(0,4)*1.5+4.2, np.arange(0,2)*1.5+7.2])#np.array([])
boxcell_y = np.concatenate([np.ones(4)*2.6, np.ones(2)*4.1])
#空⼼圆圈
circell_x = np.array([2.7, 4.2, 5.7, 7.2, 8.7])
circell_y = np.array([2.6, 4.1, 4.1, 5.6, 5.6])
#实⼼灰⾊圆
dotcell_x = np.array([2.7, 4.2, 2.7, 4.2, 5.7, 7.2, 8.7])
dotcell_y = np.array([5.6, 5.6, 7.2, 7.2, 7.2, 7.2, 7.2])
#阴影区
shodow_x = np.array([4.2, 4.2, 5.7, 5.8])
shodow_y = np.array([5.6, 7.2, 7.2, 5.5])
#带加号的⼩型圈
crosscell_x = np.array([2.5, 5.55])
crosscell_y = np.array([4.3, 5.89])
#不带加号的⼩型圈
sdotcell_x = np.array([5.3, 5.8])
sdotcell_y = np.array([6.3, 5.5])
# plot marks
#空⼼圆圈,alpha参数是透明度,⼀共5个
plt.plot(circell_x,circell_y, marker=r'$\bigodot$', markersize=22,
linewidth=0, alpha=0.6, color='k', label='Gost-Cell')
# 空⼼框,⼀共6个
plt.plot(boxcell_x,boxcell_y, marker=r'$\boxdot$', markersize=22,
linewidth=0, alpha=0.6, color='k', label='Solid-Cell')
#实⼼灰⾊圆,⼀共7个
plt.plot(dotcell_x,dotcell_y, marker=r'$\bullet$', markersize=12, linewidth=0,
alpha=0.5, color='k', label='Fluid-Cell')
#带加号的⼩型圈,两个
plt.plot(crosscell_x,crosscell_y, marker=r'$\oplus$', markersize=8,
linewidth=0, label='Fresh-Cell')
#不带加号的⼩型圈,两个
plt.plot(sdotcell_x,sdotcell_y, marker=r'$\circ$', markersize=8,
linewidth=1, alpha=0.8, color='k')
# plot shodow,⼀处
plt.fill(shodow_x, shodow_y, linewidth=0, alpha=0.2, color='k')
# textcoords属性设置为'offset points',表⽰以xytext是以xy为起点的偏移量,偏移量是像素点,呵呵。
plt.annotate('BI', xy=(5.8, 5.5), xytext=(+5, +5), textcoords='offset points')
plt.annotate('BI', xy=(5.8, 5.5), xytext=(+5, +5), textcoords='offset points')
plt.annotate('IP', xy=(5.3, 6.3), xytext=(+5, +5), textcoords='offset points')
# plot curve
# connectionstyle表⽰曲线的弯曲程度;arrowstyle表⽰箭头的风格,这⾥实际上⽤的是虚线;xycoords和textcoords指⽰xy和xytext的位置关系# ⼆者的参数是字符串'data',表⽰使⽤被注释对象的坐标系统,也就是通常说的坐标。
plt.annotate(r'$n+1$',
xy=(9.6, 6.5), xycoords='data',
xytext=(1.4, 2.4), textcoords='data', fontsize=16,
arrowprops=dict(arrow, connection))
plt.annotate(r'$n$',
xy=(9.4, 6.9), xycoords='data',
xytext=(1.4, 3.5), textcoords='data', fontsize=16,
arrowprops=dict(arrow, connection,
linestyle='dashed'))
中国传统节日网页素材
# set the figure style
ax = a()
#规定坐标轴的刻度
ax.set_xticks(np.arange(0,10,1.5)+0.4)
ax.set_yticks(np.arange(0,10,1.5)+0.4)
#设置周边的坐标轴的颜⾊为空⽩,如果不设置,图⽚四周就会有⿊⾊的坐标线。
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_color('none')
ax.spines['left'].set_color('none')
30分钟正则ax.spines['top'].set_color('none')
#调整图框的尺⼨(⽽不是改变坐标轴取值范围),使x、y 轴长度⼀致
plt.axis('scaled')#没有此项,则图形为长⽅形
#下⾯连个参数规定了最终⽣成的图⽚的坐标范围
plt.xlim(0.5,10.5)
plt.ylim(-1,9)
#控制各个轴线是否显⽰刻度标签
#plt.tick_params(labelbottom='off', labelleft='off', left='off', right='off',bottom='off', top='off')
# add the legend
#numberpoints是标签中点的个数设置,⽤scatterpoints不起作⽤;ncol表⽰每⾏有两个标签;handlelength图例中xiant线条长度;
#handletextpad线条和⽂字间距;labelspacingtu图例的⾏距;fancybox图例边框是否花边。
ax.legend(loc='lower center',numpoints=1, handlelength=2.3, handletextpad=1, labelspacing=1,
ncol=2,mode="None",borderpad=1, fancybox=True)
plt.savefig('myfig.png',dpi=400,bbox_inches='tight')
plt.show()
2.正态曲线图php7性能最好的框架
代码:
from scipy.stats import norm
normobj = norm()
x = np.arange(-4,4,0.01)
y = normobj.pdf(x)#正态曲线的概率密度函数
plot(x,y)
plot([-1,-1],[0,normobj.pdf(-1)],'k')#作⼀条直线
plot([1,1],[0,normobj.pdf(1)],'k')
plot([-2,-2],[0,normobj.pdf(-2)],'k')
plot([2,2],[0,normobj.pdf(2)],'k')
plot([-3,-3],[0,normobj.pdf(-3)],'k')
plot([3,3],[0,normobj.pdf(3)],'k')
输入链接下载视频的软件
plot([-3.9,3.9],[0,0],'k')
xlim(-3.9,3.9)
ylim(-0.1,0.42)python代码画图案
#写字符串,前两个参数分别是横坐标和纵坐标,是字符串的起始点⽽不是中点。
text(-1-0.3, -0.02, u'$\mu-\delta$', fontsize=16)
text(1-0.3, -0.02, u'$\mu+\delta$', fontsize=16)
text(-2-0.3, -0.02, u'$\mu-2\delta$', fontsize=16)
text(2-0.3, -0.02, u'$\mu+2\delta$', fontsize=16)
text(-3-0.3, -0.02, u'$\mu-3\delta$', fontsize=16)
text(3-0.3, -0.02, u'$\mu+3\delta$', fontsize=16)
plot([-1,-1],[-0.025,-0.035],'k')
plot([1,1],[-0.025,-0.035],'k')
plot([-2,-2],[-0.025,-0.055],'k')
plot([2,2],[-0.025,-0.055],'k')
plot([-3,-3],[-0.025,-0.075],'k')
plot([3,3],[-0.025,-0.075],'k')
text(-0.3, -0.035, u'$68.26\%$', fontsize=12)
text(-0.3, -0.055, u'$95.44\%$', fontsize=12)
text(-0.3, -0.075, u'$99.74\%$', fontsize=12)
#作箭头,第⼀个参数为空,表⽰交投不带标注,参数xy为箭头坐标,xytext为箭尾坐标。
annotate('',xy=(-1,-0.03),xytext=(-0.3,-0.03),arrowprops=dict(arrow,connection)) annotate('',xy=(1,-0.03),xytext=(0.3,-0.03),arrowprops=dict(arrow,connection))
annotate('',xy=(-2,-0.05),xytext=(-0.3,-0.05),arrowprops=dict(arrow,connection)) annotate('',xy=(2,-0.05),xytext=(0.3,-0.05),arrowprops=dict(arrow,connection))
annotate('',xy=(-3,-0.07),xytext=(-0.3,-0.07),arrowprops=dict(arrow,connection)) annotate('',xy=(3,-0.07),xytext=(0.3,-0.07),arrowprops=dict(arrow,connection))
#不要坐标轴
tick_params(labelbottom='off', labelleft='off', left='off', right='off',bottom='off', top='off')
#使边框不显⽰
ax = a()
ax.spines['right'].set_color('none')
相框图片素材ax.spines['bottom'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['top'].set_color('none')
savefig('norm.png',dpi=400,bbox_inches='tight')
3.云模型⽰意图

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。