Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57cb972

Browse files
committed
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.
1 parent 45fe2fd commit 57cb972

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

examples/images_contours_and_fields/interpolation_none_vs_nearest.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,22 @@
4141
fig.text(0.383, 0.90, "Interpolation = 'none'", ha = 'center')
4242
fig.text(0.75, 0.90, "Interpolation = 'nearest'", ha = 'center')
4343

44-
#Save as a png and as a pdf
45-
txt = fig.text(0.452, 0.95, 'Saved as a PNG', fontsize = 18)
46-
plt.savefig('Nearest_vs_none.png', bbox_inches = 'tight')
47-
txt.set_text('Saved as a PDF')
48-
plt.savefig('Nearest_vs_none.pdf', bbox_inches = 'tight')
44+
#If you were going to run this example on your local machine, you
45+
#would save the figure as a PNG, save the same figure as a PDF, and
46+
#then compare them. The following code would suffice.
47+
txt = fig1.text(0.452, 0.95, 'Saved as a PNG', fontsize = 18)
48+
# plt.savefig('None_vs_nearest-png.png')
49+
# txt.set_text('Saved as a PDF')
50+
# plt.savefig('None_vs_nearest-pdf.pdf')
51+
52+
#Here, however, we need to display the PDF on a webpage, which means
53+
#the PDF must be converted into an image. For the purposes of this
54+
#example, the 'Nearest_vs_none-pdf.pdf' has been pre-converted into
55+
#'Nearest_vs_none-pdf.png' at 80 dpi. We simply need to load and
56+
#display it.
57+
pdf_im_path = cbook.get_sample_data('None_vs_nearest-pdf.png')
58+
pdf_im = plt.imread(pdf_im_path)
59+
fig2 = plt.figure(figsize = [8.0, 7.5])
60+
plt.figimage(pdf_im)
61+
62+
plt.show()

0 commit comments

Comments
 (0)