Python科学绘图实例附代码

作者:金良(golden1314521@gmail.com) csdn博客http://blog.csdn.net/u012176591

1.引自知乎:如何在论文中画出漂亮的插图

这个例子源于我在知乎上看到的一个名为《如何在论文中画出漂亮的插图》的话题(网址为http://www.zhihu.com/question/21664179),这个例子让我对Python绘制插图的能力感到震撼,于是我研摩了该例子的源码并对其不足做了一些修正。
首先看插图,吃精了吧

这里写图片描述

还有源码,我加了详细的注释,应该不难理解

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,5.6,5.6])

#实心灰色圆
dotcell_x = np.array([2.7,2.7,8.7])
dotcell_y = np.array([5.6,7.2])

#阴影区
shodow_x = np.array([4.2,5.8])
shodow_y = np.array([5.6,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$',label='Solid-Cell')

#实心灰色圆,一共7个
plt.plot(dotcell_x,dotcell_y,marker=r'$\bullet$',markersize=12,alpha=0.5,label='Fluid-Cell')

#带加号的小型圈,两个
plt.plot(crosscell_x,crosscell_y,marker=r'$\oplus$',markersize=8,label='Fresh-Cell')

#不带加号的小型圈,两个
plt.plot(sdotcell_x,sdotcell_y,marker=r'$\circ$',linewidth=1,alpha=0.8,color='k')

# plot shodow,一处
plt.fill(shodow_x,shodow_y,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('IP',xy=(5.3,6.3),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(arrowstyle="-",connectionstyle="arc3,rad=-.2"))
plt.annotate(r'$n$',xy=(9.4,6.9),3.5),rad=-.2",linestyle='dashed'))
plt.grid(True,linewidth=2)

# set the figure style
ax = plt.gca()

#规定坐标轴的刻度
ax.set_xticks(np.arange(0,10,1.5)+0.4)
ax.set_yticks(np.arange(0,1.5)+0.4)

#设置周边的坐标轴的颜色为空白,如果不设置,图片四周就会有黑色的坐标线。
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_color('none')
ax.spines['left'].set_color('none')
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()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100

2.正态曲线图

这里写图片描述

代码

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],normobj.pdf(1)],'k')

plot([-2,-2],normobj.pdf(-2)],'k')
plot([2,2],normobj.pdf(2)],'k')

plot([-3,-3],normobj.pdf(-3)],'k')
plot([3,3],normobj.pdf(3)],'k')

plot([-3.9,3.9],0],'k')

xlim(-3.9,3.9)
ylim(-0.1,0.42)

#写字符串,前两个参数分别是横坐标和纵坐标,是字符串的起始点而不是中点。
text(-1-0.3,-0.02,u'$\mu-\delta$',fontsize=16)
text(1-0.3,u'$\mu+\delta$',fontsize=16)
text(-2-0.3,u'$\mu-2\delta$',fontsize=16)
text(2-0.3,u'$\mu+2\delta$',fontsize=16)
text(-3-0.3,u'$\mu-3\delta$',fontsize=16)
text(3-0.3,u'$\mu+3\delta$',fontsize=16)

plot([-1,[-0.025,-0.035],'k')
plot([1,-0.055],-0.075],'k')

text(-0.3,-0.035,u'$68.26\%$',fontsize=12)
text(-0.3,-0.055,u'$95.44\%$',-0.075,u'$99.74\%$',fontsize=12)

#作箭头,第一个参数为空,表示交投不带标注,参数xy为箭头坐标,xytext为箭尾坐标。
annotate('',xy=(-1,-0.03),xytext=(-0.3,arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))
annotate('',xy=(1,xytext=(0.3,connectionstyle="arc3"))

annotate('',xy=(-2,-0.05),xy=(2,xy=(-3,-0.07),xy=(3,connectionstyle="arc3"))

#不要坐标轴
tick_params(labelbottom='off',labelleft='off',left='off',right='off',bottom='off',top='off')

#使边框不显示
ax = plt.gca()
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',bBox_inches='tight')
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

3.云模型示意图

这里写图片描述

import numpy as np
import matplotlib.pyplot as plt
%pylab
import random
def backcloud(cloudpara,n=1000):
    Ex = cloudpara[0]
    En = cloudpara[1]
    He = cloudpara[2]

    xd = []
    yd = []

    for i in range(n):
        Enn = random.gauss(0,1)*He + En
        x = random.gauss(0,1)*Enn + Ex
        y = np.exp(-(x-Ex)**2/(2*Enn**2))
        xd.append(x)
        yd.append(y)

    return xd,yd

def expcurve(myex=0,mydelta=1,myshift=4):
    x = np.arange(-myshift,myshift,0.01)
    y = np.exp(-0.5*(x-myex)**2/mydelta**2)
    return x,y

x,y = backcloud((0,1,0.1),3000)
plot(x,y,'.k')
x,y = expcurve(0,1.3,4)
plot(x,'b')
x,0.7,'b')
annotate(u'$\mu_2$',xy=(-1.22,0.63),xytext=(-2.7,connectionstyle="arc3"),fontsize=20)
annotate(u'$\mu_1$',xy=(-0.889,0.47),fontsize=20)

plot([4,4],0.4],'k')
plot([3.2,3.2],0.2],'k')
plot([2.54,2.54],0.3],'k')
plot([0,'k')

text(4-0.5,0.42,u'$3(E_n+3H_e)$',fontsize=14)
text(2.54-0.5,0.32,u'$3(E_n-3H_e)$',fontsize=14)
text(3.2-0.1,0.22,u'$3S$',fontsize=14)
text(0-0.1,u'$E_x$',fontsize=14)

xlim(-4,5)
ax = plt.gca()
xlabel('x')
ylabel(u'$\mu$')
savefig('cloudmodelfeature.png',dpi=700,bBox_inches='tight')
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

4. scatter-hist图

这里写图片描述

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter

# the random data
x = np.random.randn(3000)
y = np.random.randn(3000)

nullfmt   = NullFormatter()         # no labels

# deFinitions for the axes
left,width = 0.1,0.65
bottom,height = 0.1,0.65
bottom_h = left_h = left+width+0.02

#左下角较大的区域,参数为画布的比例
rect_scatter = [left,bottom,width,height]
#上面的条形图区域
rect_histx = [left,bottom_h,0.2]
#右边的条形图区域
rect_histy = [left_h,0.2,height]

# figsize参数是以inch为单位,在桌面上显示的画布的大小
plt.figure(1,figsize=(8,8))

axScatter = plt.axes(rect_scatter)
axHistx = plt.axes(rect_histx)
axHisty = plt.axes(rect_histy)

# no labels
#axHistx的x坐标无刻度
axHistx.xaxis.set_major_formatter(nullfmt)
#axHisty的y坐标无刻度
axHisty.yaxis.set_major_formatter(nullfmt)

# the scatter plot:
#画散点图
axScatter.scatter(x,y)

# Now determine nice limits by hand:
binwidth = 0.25
xymax = np.max( [np.max(np.fabs(x)),np.max(np.fabs(y))] )
lim = xymax+0.1#( int(xymax/binwidth) + 1) * binwidth

axScatter.set_xlim( (-lim,lim) )
axScatter.set_ylim( (-lim,lim) )

bins = np.arange(-lim,lim + binwidth,binwidth)
axHistx.hist(x,bins=bins)
axHisty.hist(y,bins=bins,orientation='horizontal')

axHistx.set_xlim( axScatter.get_xlim() )
axHistx.set_yticklabels(labels=['0','50','100','150','200','250','300','350'],rotation=47)

axHisty.set_ylim( axScatter.get_ylim() )
axHisty.set_xticklabels(labels=['0',rotation=-47)

#plt.show()
savefig('scatter-hist.png',bBox_inches='tight')

 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

5.若干类型的图例

这里写图片描述

6.热图

这里写图片描述

import matplotlib.pyplot as plt
import numpy as np

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


xx,yy = np.meshgrid(np.linspace(-3,3,50),np.linspace(-3,50))
zz = f(xx,yy)
plt.imshow(zz,origin='lower',extent=[xx.min(),xx.max(),yy.min(),yy.max()])
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

If you don’t need an equal aspect you can set aspect to auto :

imshow(random.rand(8,90),interpolation='nearest',aspect='auto')
 
  • 1

效果图如下:

这里写图片描述

data2show = np.random.random((242,8))

fig,ax= plt.subplots()

plt.imshow(data2show,aspect='auto')
cb = plt.colorbar()
cb.ax.tick_params(labelsize=25)


cb.set_label(r'mean value of ratings',labelpad=10,y=0.45) #colorbar的标签和位置
text = cb.ax.yaxis.label
font = matplotlib.font_manager.FontProperties(size=30)
text.set_font_properties(font)


plt.yticks([5,50,100,150,200,240],[250,fontsize = 30)
plt.xticks([0.5,1.4,2.59,3.3,4.5,5.5,6.7,7.5],['male-young','male-adult','male-middle-age','male-old','female-young','female-adult','female-middle-age','female-old'],fontsize = 30,rotation=-13)

plt.xlabel('Gender-age groups',{'fontname':'STFangsong','fontsize':52})
plt.ylabel('List of movies','fontsize':52})

ax.spines['right'].set_color('none')
ax.spines['bottom'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['top'].set_color('none')
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

效果如下:

这里写图片描述

7.为点加标签

这里写图片描述

import numpy as np
import matplotlib.pyplot as plt

N = 10
data = np.random.random((N,4))
labels = ['point{0}'.format(i) for i in range(N)]
plt.subplots_adjust(bottom = 0.1)
plt.scatter(
    data[:,0],data[:,1],marker = 'o',c = data[:,2],s = data[:,3]*1500,
    cmap = plt.get_cmap('Spectral'))
for label,x,y in zip(labels,data[:,1]):
    plt.annotate(
        label,xy = (x,y),xytext = (-20,20),textcoords = 'offset points',ha = 'right',va = 'bottom',bBox = dict(Boxstyle = 'round,pad=0.5',fc = 'yellow',alpha = 0.5),arrowprops = dict(arrowstyle = '->',connectionstyle = 'arc3,rad=0'))

plt.show()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

8.导入已有图片并进行修饰

这里写图片描述

fig = plt.figure()
rect=[0.1,0.1,0.8,0.8]
axprops = dict(xticks=[],yticks=[])

ax0=fig.add_axes(rect,label='ax0',**axprops)
imgP = plt.imread('Portland.png')
ax0.imshow(imgP)   

ax1=fig.add_axes(rect,label='ax1',frameon=False)
x = linspace(0,100)
y = sin(x)
ax1.plot(x,y)
ax1.set_xlim([-2,12])
ax1.set_ylim([-5,12])


ax2=fig.add_axes(rect,label='ax2',frameon=False,**axprops)
shodow_x = np.array([4.2,5.8])
shodow_y = np.array([5.6,5.5])
ax2.set_xlim([-2,12])
ax2.set_ylim([-5,12])
ax2.fill(shodow_x,alpha=0.4,color='r')
ax2.annotate('plot shadow area',xy=(5.7,7.2),xytext=(4.7,3.3),textcoords = 'offset points',fontsize=20)



plt.show()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

9.热度方格图

这里写图片描述

data = np.array([[ 0.45833279,0.35737994,0.54257486,0.66908835],[ 0.19544843,0.48287855,0.97316904,0.25445816],[ 0.44500619,0.88060579,0.74509425,0.65703952],[ 0.80474809,0.48011234,0.05086501,0.47188907]])
fig,ax = plt.subplots()
heatmap = ax.pcolor(data,cmap=plt.cm.Greys)

# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[0])+0.5,minor=False)
ax.set_yticks(np.arange(data.shape[1])+0.5,minor=False)

# want a more natural,table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()

ax.set_xticklabels(['a','b','c','d'],minor=False)
ax.set_yticklabels(['A','B','C','D'],minor=False)

cbar = plt.colorbar(heatmap) 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

10. 箱线图

这里写图片描述

np.random.seed(10)
data_to_plot = [np.random.normal(100,200),np.random.normal(80,30,np.random.normal(90,20,np.random.normal(70,25,200)]

fig = plt.figure(1,figsize=(9,6))
# Create an axes instance
ax = fig.add_subplot(111)

## add patch_artist=True option to ax.Boxplot() 
## to get fill color
bp = ax.Boxplot(data_to_plot,patch_artist=True)

## change outline color,fill color and linewidth of the Boxes
for Box in bp['Boxes']:
    # change outline color
    Box.set( color='#7570b3',linewidth=2)
    # change fill color
    Box.set( facecolor = '#1b9e77' )

## change color and linewidth of the whiskers
for whisker in bp['whiskers']:
    whisker.set(color='y',linewidth=2)

## change color and linewidth of the caps
for cap in bp['caps']: # 上下的帽子
    cap.set(color='#7570b3',linewidth=2)

## change color and linewidth of the medians
for median in bp['medians']: #中值
    median.set(color='r',linewidth=2)

## change the style of fliers and their fill
for flier in bp['fliers']: #异常值
    flier.set(marker='o',alpha=0.5)
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

双纵坐标

legend不在一块

这里写图片描述

x = np.arange(0.,np.e,0.01)
y1 = np.exp(-x)
y2 = np.log(x+1)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x,y1,label='bb');
ax1.set_ylabel('Y values for exp(-x)');
ax2 = ax1.twinx() # this is the important function
ax2.plot(x,y2,'r',label = 'aa');
ax2.set_xlim([0,np.e]);
ax2.set_ylabel('Y values for ln(x)');
ax2.set_xlabel('Same X for both exp(-x) and ln(x)');
ax1.legend()
ax2.legend(loc=0)
plt.show()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

legend放一块儿

这里写图片描述

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc

time = np.arange(10)
data1,data2 = np.random.random(10)*30,np.random.random(10)*100-10

fig = plt.figure()
ax = fig.add_subplot(111)

lns1 = ax.plot(time,data1,'-',label = 'data1')

ax2 = ax.twinx()
lns2 = ax2.plot(time,data2,'-r',label = 'data2')
ax2.tick_params(axis='y',colors='red') # 刻度颜色
ax2.spines['right'].set_color('red') # 纵轴颜色
setp(ax2.get_yticklabels(),color='r') # label颜色

lns = lns1+lns2
labs = [l.get_label() for l in lns]
ax.legend(lns,labs,loc=0)

ax.grid()
ax.set_xlabel("Time")
ax.set_ylabel(r"Radiation ")
ax2.set_ylabel(r"Temperature")

ax2.set_ylim(-20,100)
ax.set_ylim(0,35)
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

多个子图共用一个legend

这里写图片描述

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import subplotZero

width = 1 # 两条柱之间的距离
num = 5 #柱的个数
ind = np.arange(num)

fig = plt.figure(figsize=(15,4))
ax = subplotZero(fig,1)
ax1 = fig.add_subplot(ax)

means = [0.6481,0.6215,0.58,0.56,0.442] 
stds = [0.0129,0.0119,0.01,0.009,0.003]

plt.bar(0.2+ind,means,0.6*width,color=['k','y','r'],linewidth = 0.1,yerr=stds,error_kw=dict(elinewidth=1.5,ecolor='green'))
plt.axis([0,5,0,1])
plt.ylabel(u'wPrecision')
plt.grid()
plt.xticks([])



ax = subplotZero(fig,2)
ax2 = fig.add_subplot(ax)
means = [0.341,0.39,0.48,0.582] 
stds = [0.0109,0.0149,0.02,0.011,0.009]
plt.bar(0.2+ind,1])
plt.ylabel(u'wRecall')
plt.grid()
plt.xticks([])

ax = subplotZero(fig,3)
ax3 = fig.add_subplot(ax)
means = [0.68,0.6415,0.6,0.548] 
stds = [0.02,0.0099,0.007]
label = plt.bar(0.2+ind,1])
plt.ylabel(u'wF1')
plt.grid()
plt.xticks([])

fig.legend((label[0],label[1],label[2],label[3],label[4]),('SVD-Single','SVD-Multiple','JNE','SNE','R2P'),'upper center',ncol=5)
savefig('comparison_baseline.png',dpi=250,bBox_inches='tight')
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-095d4a0b23.css" rel="stylesheet">
                </div>
</article>

原文地址:https://blog.csdn.net/pary__for

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


我最近重新拾起了计算机视觉,借助Python的opencv还有face_recognition库写了个简单的图像识别demo,额外定制了一些内容,原本想打包成exe然后发给朋友,不过在这当中遇到了许多小问题,都解决了,记录一下踩过的坑。 1、Pyinstaller打包过程当中出现warning,跟d
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Pooling在中文当中的意思是“池化”,在神经网络当中非常常见,通常用的比较多的一种是Max Pooling,具体操作如下图: 结合图像理解,相信你也会大概明白其中的本意。不过Pooling并不是只可以选取2x2的窗口大小,即便是3x3,
记得大一学Python的时候,有一个题目是判断一个数是否是复数。当时觉得比较复杂不好写,就琢磨了一个偷懒的好办法,用异常处理的手段便可以大大程度帮助你简短代码(偷懒)。以下是判断整数和复数的两段小代码: 相信看到这里,你也有所顿悟,能拓展出更多有意思的方法~
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic histogram2. 数据分布与密度信息显示 Control rug and density on seaborn histogram3. 带箱形图的直方图 Histogram with a boxplot on t
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic violinplot2. 小提琴图样式自定义 Custom seaborn violinplot3. 小提琴图颜色自定义 Control color of seaborn violinplot4. 分组小提琴图 Group
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic density plot2. 核密度图的区间控制 Control bandwidth of density plot3. 多个变量的核密度图绘制 Density plot of several variables4. 边
首先 import tensorflow as tf tf.argmax(tenso,n)函数会返回tensor中参数指定的维度中的最大值的索引或者向量。当tensor为矩阵返回向量,tensor为向量返回索引号。其中n表示具体参数的维度。 以实际例子为说明: import tensorflow a
seaborn学习笔记章节 seaborn是一个基于matplotlib的Python数据可视化库。seaborn是matplotlib的高级封装,可以绘制有吸引力且信息丰富的统计图形。相对于matplotlib,seaborn语法更简洁,两者关系类似于numpy和pandas之间的关系,seabo
Python ConfigParser教程显示了如何使用ConfigParser在Python中使用配置文件。 文章目录 1 介绍1.1 Python ConfigParser读取文件1.2 Python ConfigParser中的节1.3 Python ConfigParser从字符串中读取数据
1. 处理Excel 电子表格笔记(第12章)(代码下载) 本文主要介绍openpyxl 的2.5.12版处理excel电子表格,原书是2.1.4 版,OpenPyXL 团队会经常发布新版本。不过不用担心,新版本应该在相当长的时间内向后兼容。如果你有新版本,想看看它提供了什么新功能,可以查看Open
1. 发送电子邮件和短信笔记(第16章)(代码下载) 1.1 发送电子邮件 简单邮件传输协议(SMTP)是用于发送电子邮件的协议。SMTP 规定电子邮件应该如何格式化、加密、在邮件服务器之间传递,以及在你点击发送后,计算机要处理的所有其他细节。。但是,你并不需要知道这些技术细节,因为Python 的
文章目录 12 绘图实例(4) Drawing example(4)1. Scatterplot with varying point sizes and hues(relplot)2. Scatterplot with categorical variables(swarmplot)3. Scat
文章目录 10 绘图实例(2) Drawing example(2)1. Grouped violinplots with split violins(violinplot)2. Annotated heatmaps(heatmap)3. Hexbin plot with marginal dist
文章目录 9 绘图实例(1) Drawing example(1)1. Anscombe’s quartet(lmplot)2. Color palette choices(barplot)3. Different cubehelix palettes(kdeplot)4. Distribution
Python装饰器教程展示了如何在Python中使用装饰器基本功能。 文章目录 1 使用教程1.1 Python装饰器简单示例1.2 带@符号的Python装饰器1.3 用参数修饰函数1.4 Python装饰器修改数据1.5 Python多层装饰器1.6 Python装饰器计时示例 2 参考 1 使
1. 用GUI 自动化控制键盘和鼠标第18章 (代码下载) pyautogui模块可以向Windows、OS X 和Linux 发送虚拟按键和鼠标点击。根据使用的操作系统,在安装pyautogui之前,可能需要安装一些其他模块。 Windows: 不需要安装其他模块。OS X: sudo pip3
文章目录 生成文件目录结构多图合并找出文件夹中相似图像 生成文件目录结构 生成文件夹或文件的目录结构,并保存结果。可选是否滤除目录,特定文件以及可以设定最大查找文件结构深度。效果如下: root:[z:/] |--a.py |--image | |--cat1.jpg | |--cat2.jpg |
文章目录 VENN DIAGRAM(维恩图)1. 具有2个分组的基本的维恩图 Venn diagram with 2 groups2. 具有3个组的基本维恩图 Venn diagram with 3 groups3. 自定义维恩图 Custom Venn diagram4. 精致的维恩图 Elabo
mxnet60分钟入门Gluon教程代码下载,适合做过深度学习的人使用。入门教程地址: https://beta.mxnet.io/guide/getting-started/crash-course/index.html mxnet安装方法:pip install mxnet 1 在mxnet中使
文章目录 1 安装2 快速入门2.1 基本用法2.2 输出图像格式2.3 图像style设置2.4 属性2.5 子图和聚类 3 实例4 如何进一步使用python graphviz Graphviz是一款能够自动排版的流程图绘图软件。python graphviz则是graphviz的python实