Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c239e5c8 authored by Pascal Denis's avatar Pascal Denis
Browse files

add scatter 3d

git-svn-id: https://scm.gforge.inria.fr/authscm/cfourrie/svn/lingwb/metagger/trunk@2731 dc05b511-7f1d-0410-9f1c-d6f32a2df9e4
parent 205f4beb
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
import matplotlib
from mpl_toolkits.mplot3d import axes3d
from matplotlib import cm from matplotlib import cm
import pylab import pylab
import random import random
import numpy as np import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
...@@ -18,24 +21,28 @@ def plot_3D(triple_list,type="wireframe",x_label="R",y_label="C",z_label="Value" ...@@ -18,24 +21,28 @@ def plot_3D(triple_list,type="wireframe",x_label="R",y_label="C",z_label="Value"
x_list,y_list,z_list = zip(*triple_list) x_list,y_list,z_list = zip(*triple_list)
z_dict = dict([((x,y),z) for (x,y,z) in triple_list]) z_dict = dict([((x,y),z) for (x,y,z) in triple_list])
X, Y = np.meshgrid( x_list,y_list ) X, Y = np.meshgrid( x_list,y_list )
Z = np.zeros((len(Y), len(X))) #X = np.array([x_list]*len(x_list))
#Y = np.array([y_list]*len(y_list))
Z = np.zeros((len(X), len(Y)))
for i in range(len(X)): for i in range(len(X)):
for j in range(len(Y)): for j in range(len(Y)):
Z[j,i] = z_dict[x_list[i],y_list[j]] Z[j,i] = z_dict[x_list[i],y_list[j]]
if type=="wireframe": if type=="wireframe":
ax.plot_wireframe(X,Y,Z,rstride=10, cstride=10) ax.plot_wireframe(X,Y,Z,rstride=10, cstride=10,linestyle="dotted")
elif type=="surface": elif type=="surface":
ax.plot_surface(X,Y,Z, rstride=10, cstride=10, cmap=cm.jet) ax.plot_surface(X,Y,Z, rstride=10, cstride=10, cmap=cm.jet)
elif type=="contour": elif type=="contour":
ax.contour3D(X,Y,Z) ax.contour3D(X,Y,Z)
elif type=="scatter":
ax.scatter3D(x_list,y_list,z_list)
else: else:
raise ValueError("Unknown plot type "+str(type)) raise ValueError("Unknown plot type "+str(type))
ax.set_xlabel( x_label ) ax.set_xlabel( x_label )
ax.set_ylabel( y_label ) ax.set_ylabel( y_label )
ax.set_zlabel( z_label ) ax.set_zlabel( z_label )
#if title: windowtitle(title) #if title: windowtitle(title)
#pylab.show._needmain=False #pylab.show._needmain=False
...@@ -59,15 +66,45 @@ def plot_2D(x_values,y_values,x_label="X",y_label="Y",title=None): ...@@ -59,15 +66,45 @@ def plot_2D(x_values,y_values,x_label="X",y_label="Y",title=None):
def plot_2D_contour(triple_list,x_label="X",y_label="Y",title=None):
x_list,y_list,z_list = zip(*triple_list)
z_dict = dict([((x,y),z) for (x,y,z) in triple_list])
X, Y = np.meshgrid( x_list,y_list )
Z = np.zeros((len(X), len(Y)))
for i in range(len(X)):
for j in range(len(Y)):
Z[j,i] = z_dict[x_list[i],y_list[j]]
cmap = cm.get_cmap('jet', 100) # 10 discrete colors
im = pylab.imshow(Z, cmap=cmap, interpolation='bilinear')
#pylab.axis('off')
pylab.colorbar()
pylab.xlabel( x_label )
pylab.ylabel( y_label )
pylab.show()
# plt.figure()
# CS = plt.contour(X, Y, Z)
# plt.clabel(CS, inline=1, fontsize=10)
# plt.title(title)
return
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
import optparse import optparse
usage = "usage: %prog [options] <input_file>" usage = "usage: %prog [options] <input_file>"
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option("-d", "--dimension", type=int, default=3) parser.add_option("-d", "--dimension", type=int, default=3)
parser.add_option("-t", "--type", choices=["wireframe","scatter","surface","contour"], default="wireframe")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
result_file = args[0] result_file = args[0]
...@@ -100,10 +137,11 @@ if __name__ == '__main__': ...@@ -100,10 +137,11 @@ if __name__ == '__main__':
# x_label = 'Dictionary size (in # of lemmas)' # x_label = 'Dictionary size (in # of lemmas)'
y_label = 'Accuracy on test data' y_label = 'Accuracy on test data'
# y_label = 'Dictionary size (in # of lemmas)' # y_label = 'Dictionary size (in # of lemmas)'
plot_2D( X,Z, x_label, y_label, title="POS Tagger learning curve" ) plot_2D( X, Y, x_label, y_label, title="POS Tagger learning curve" )
# plot_2D_contour( scores, x_label, y_label, title="POS Tagger learning curve" )
else: else:
plot_3D(scores,type="wireframe", plot_3D(scores,type=options.type,
x_label="Training size (in # of sentences)", x_label="Training size (in # of sentences)",
y_label="Dictionary size (in # of lemmas)", y_label="Dictionary size (in # of lemmas)",
z_label="Accuracy on test data", z_label="Accuracy on test data",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment