From b4dd511335daff02a12f5306fc232915bb05e6a1 Mon Sep 17 00:00:00 2001 From: Benjamin Reedlunn Date: Sat, 19 Apr 2014 15:26:06 -0600 Subject: [PATCH 1/3] Update interpolation_none_vs_nearest.py Minor rewording to "interpolation_none_vs_nearest.py" description. --- .../interpolation_none_vs_nearest.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/images_contours_and_fields/interpolation_none_vs_nearest.py b/examples/images_contours_and_fields/interpolation_none_vs_nearest.py index 8ec32d06c538..d79b4b99923b 100644 --- a/examples/images_contours_and_fields/interpolation_none_vs_nearest.py +++ b/examples/images_contours_and_fields/interpolation_none_vs_nearest.py @@ -2,12 +2,13 @@ Displays the difference between interpolation = 'none' and interpolation = 'nearest'. -Interpolation = 'none' and 'nearest' are equivalent when converting a -figure to an image file, such as a PNG. Interpolation = 'none' -and interpolation = 'nearest' behave quite differently, however, when -converting a figure to a vector graphics file, such as a PDF. As shown, -Interpolation = 'none' works well when a big image is scaled down, while -interpolation = 'nearest' works well when a small image is blown up. +Interpolation = 'none' and interpolation = 'nearest' are equivalent when +converting a figure to an image file, such as a PNG. +Interpolation = 'none' and interpolation = 'nearest' behave quite +differently, however, when converting a figure to a vector graphics file, +such as a PDF. As shown, Interpolation = 'none' works well when a big +image is scaled down, while interpolation = 'nearest' works well when a +small image is blown up. """ import numpy as np @@ -44,4 +45,4 @@ txt = fig.text(0.452, 0.95, 'Saved as a PNG', fontsize = 18) plt.savefig('Nearest_vs_none.png', bbox_inches = 'tight') txt.set_text('Saved as a PDF') -plt.savefig('Nearest_vs_none.pdf', bbox_inches = 'tight') \ No newline at end of file +plt.savefig('Nearest_vs_none.pdf', bbox_inches = 'tight') From 45fe2fd0b2bf6949020b3d10f1a8f16d91804f74 Mon Sep 17 00:00:00 2001 From: Benjamin Reedlunn Date: Tue, 22 Apr 2014 21:46:06 -0600 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d0e2c660797c..dcd185a3e47e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2014-04-22 Added an example showing the difference between + interpolation = 'none' and interpolation = 'nearest' in + `imshow()` when saving vector graphics files. + 2014-04-10 Fixed the triangular marker rendering error. The "Up" triangle was rendered instead of "Right" triangle and vice-versa. From 57cb972930ce7f257d7b5fd63c2e264eb0899afc Mon Sep 17 00:00:00 2001 From: Benjamin Reedlunn Date: Sun, 27 Apr 2014 09:33:28 -0600 Subject: [PATCH 3/3] Update interpolation_none_vs_nearest.py Changed the last few lines so that the auto-documentation build process correctly displays the results of the example. --- .../interpolation_none_vs_nearest.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/images_contours_and_fields/interpolation_none_vs_nearest.py b/examples/images_contours_and_fields/interpolation_none_vs_nearest.py index d79b4b99923b..eaa7d3332574 100644 --- a/examples/images_contours_and_fields/interpolation_none_vs_nearest.py +++ b/examples/images_contours_and_fields/interpolation_none_vs_nearest.py @@ -41,8 +41,22 @@ fig.text(0.383, 0.90, "Interpolation = 'none'", ha = 'center') fig.text(0.75, 0.90, "Interpolation = 'nearest'", ha = 'center') -#Save as a png and as a pdf -txt = fig.text(0.452, 0.95, 'Saved as a PNG', fontsize = 18) -plt.savefig('Nearest_vs_none.png', bbox_inches = 'tight') -txt.set_text('Saved as a PDF') -plt.savefig('Nearest_vs_none.pdf', bbox_inches = 'tight') +#If you were going to run this example on your local machine, you +#would save the figure as a PNG, save the same figure as a PDF, and +#then compare them. The following code would suffice. +txt = fig1.text(0.452, 0.95, 'Saved as a PNG', fontsize = 18) +# plt.savefig('None_vs_nearest-png.png') +# txt.set_text('Saved as a PDF') +# plt.savefig('None_vs_nearest-pdf.pdf') + +#Here, however, we need to display the PDF on a webpage, which means +#the PDF must be converted into an image. For the purposes of this +#example, the 'Nearest_vs_none-pdf.pdf' has been pre-converted into +#'Nearest_vs_none-pdf.png' at 80 dpi. We simply need to load and +#display it. +pdf_im_path = cbook.get_sample_data('None_vs_nearest-pdf.png') +pdf_im = plt.imread(pdf_im_path) +fig2 = plt.figure(figsize = [8.0, 7.5]) +plt.figimage(pdf_im) + +plt.show()