diff --git a/doc/logos/scikit-learn-logo-thumb.png b/doc/logos/scikit-learn-logo-thumb.png new file mode 100644 index 0000000000000000000000000000000000000000..e67908194c8f0b012856d2b7bcd08b6a7ba1d72e Binary files /dev/null and b/doc/logos/scikit-learn-logo-thumb.png differ diff --git a/doc/sphinxext/gen_rst.py b/doc/sphinxext/gen_rst.py index c61e336327ebde90a459457fe1a402c3acbbc401..0cf3840302152bf10f5a073401c53e703b9ea150 100644 --- a/doc/sphinxext/gen_rst.py +++ b/doc/sphinxext/gen_rst.py @@ -110,6 +110,29 @@ def generate_example_rst(app): fhindex = file(os.path.join(root_dir, 'index.rst'), 'w') fhindex.write("""\ +.. raw:: html + + <style type="text/css"> + .figure { + float: left; + margin: 10px; + height: auto; + width: auto; + height: 200px; + width: 180px; + } + + .figure img { + display: inline; + margin: 3px; + } + + .figure .caption { + width: 170px; + text-align: center !important; + } + </style> + Examples ======== @@ -119,8 +142,6 @@ Examples # better than nested. generate_dir_rst('.', fhindex, example_dir, root_dir, plot_gallery) for dir in sorted(os.listdir(example_dir)): - if dir == '.svn': - continue if os.path.isdir(os.path.join(example_dir, dir)): generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery) fhindex.flush() @@ -144,9 +165,9 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery): return fhindex.write(""" + %s -.. toctree:: """ % file(os.path.join(src_dir, 'README.txt')).read()) if not os.path.exists(target_dir): @@ -154,7 +175,17 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery): for fname in sorted(os.listdir(src_dir)): if fname.endswith('py'): generate_file_rst(fname, target_dir, src_dir, plot_gallery) - fhindex.write(' %s\n' % (os.path.join(dir, fname[:-3]))) + thumb = os.path.join(dir, 'images', 'thumb', fname[:-3] + '.png') + fhindex.write('.. figure:: %s\n\n' % thumb) + link_name = os.path.join(dir, fname).replace(os.path.sep, '_') + if link_name.startswith('._'): + link_name = link_name[2:] + fhindex.write(' :ref:`example_%s`\n\n' % link_name) + fhindex.write(""" +.. raw:: html + + <div style="clear: both"></div> + """) def generate_file_rst(fname, target_dir, src_dir, plot_gallery): @@ -178,15 +209,18 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery): # The following is a list containing all the figure names figure_list = [] + image_dir = os.path.join(target_dir, 'images') + thumb_dir = os.path.join(image_dir, 'thumb') + if not os.path.exists(image_dir): + os.makedirs(image_dir) + if not os.path.exists(thumb_dir): + os.makedirs(thumb_dir) + image_path = os.path.join(image_dir, image_fname) + thumb_file = os.path.join(thumb_dir, fname[:-3] + '.png') if plot_gallery and fname.startswith('plot'): # generate the plot as png image if file name # starts with plot and if it is more recent than an # existing image. - image_dir = os.path.join(target_dir, 'images') - if not os.path.exists(image_dir): - os.makedirs(image_dir) - - image_path = os.path.join(image_dir, image_fname) first_image_file = image_path % 1 if (not os.path.exists(first_image_file) or @@ -228,7 +262,16 @@ def generate_file_rst(fname, target_dir, src_dir, plot_gallery): figure_list = [f[len(image_dir):] for f in glob.glob(image_path % '[1-9]')] #for f in glob.glob(image_path % '*')] + + # generate thumb file this_template = plot_rst_template + from matplotlib import image + if os.path.exists(first_image_file): + image.thumbnail(first_image_file, thumb_file, 0.2) + + if not os.path.exists(thumb_file): + # create something not to replace the thumbnail + shutil.copy('logos/scikit-learn-logo-thumb.png', thumb_file) docstring, short_desc, end_row = extract_docstring(example_file) diff --git a/examples/covariance/plot_covariance_estimation.py b/examples/covariance/plot_covariance_estimation.py index c01747f6ebd16e7c92801a140b8461b0b01bd79c..178caceecfe2c6cfd40b0ec2c2cb04d3f1efe31e 100644 --- a/examples/covariance/plot_covariance_estimation.py +++ b/examples/covariance/plot_covariance_estimation.py @@ -68,7 +68,6 @@ loglik_real = -log_likelihood(emp_cov, linalg.inv(real_cov)) ############################################################################### # Plot results -pl.figure(-1) pl.title("Regularized covariance: likelihood and shrinkage coefficient") pl.xlabel('Shrinkage') pl.ylabel('Negative log-likelihood') diff --git a/examples/manifold/plot_lle_digits.py.prof b/examples/manifold/plot_lle_digits.py.prof new file mode 100644 index 0000000000000000000000000000000000000000..2d30366716f99aa15baa8284df16ef3f2900d2b0 Binary files /dev/null and b/examples/manifold/plot_lle_digits.py.prof differ diff --git a/examples/plot_precision_recall.py b/examples/plot_precision_recall.py index f62b21d0392fb3b7d1e509f087207f2ec25d1ccb..8d4f1a9a0ea5ec5df597b27a3988993f1ae14907 100644 --- a/examples/plot_precision_recall.py +++ b/examples/plot_precision_recall.py @@ -40,7 +40,6 @@ precision, recall, thresholds = precision_recall_curve(y[half:], probas_[:,1]) area = auc(recall, precision) print "Area Under Curve: %0.2f" % area -pl.figure(-1) pl.clf() pl.plot(recall, precision, label='Precision-Recall curve') pl.xlabel('Recall') diff --git a/examples/plot_roc.py b/examples/plot_roc.py index e9863d00055398bfe9f31fb705a230ff23c8ec33..b7c529c041a01c143f12d2a82bd863526a7bbc70 100644 --- a/examples/plot_roc.py +++ b/examples/plot_roc.py @@ -44,7 +44,6 @@ roc_auc = auc(fpr, tpr) print "Area under the ROC curve : %f" % roc_auc # Plot ROC curve -pl.figure(-1) pl.clf() pl.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc) pl.plot([0, 1], [0, 1], 'k--') diff --git a/examples/plot_train_error_vs_test_error.py b/examples/plot_train_error_vs_test_error.py index 26a367fa3d2c1c90cb3935ab2a78e7abbe8422a1..12da0c8edcd50894f3f4132677c5e8cc0077b81c 100644 --- a/examples/plot_train_error_vs_test_error.py +++ b/examples/plot_train_error_vs_test_error.py @@ -39,7 +39,8 @@ enet = linear_model.ElasticNet(rho=0.7) train_errors = list() test_errors = list() for alpha in alphas: - enet.fit(X_train, y_train, alpha=alpha) + enet.set_params(alpha=alpha) + enet.fit(X_train, y_train) train_errors.append(enet.score(X_train, y_train)) test_errors.append(enet.score(X_test, y_test)) @@ -48,7 +49,8 @@ alpha_optim = alphas[i_alpha_optim] print "Optimal regularization parameter : %s" % alpha_optim # Estimate the coef_ on full data with optimal regularization parameter -coef_ = enet.fit(X, y, alpha=alpha_optim).coef_ +enet.set_params(alpha=alpha_optim) +coef_ = enet.fit(X, y).coef_ ############################################################################### # Plot results functions