Title: Bug when saving to vector format (pdf, svg, eps) · Issue #2831 · matplotlib/matplotlib · GitHub
Open Graph Title: Bug when saving to vector format (pdf, svg, eps) · Issue #2831 · matplotlib/matplotlib
X Title: Bug when saving to vector format (pdf, svg, eps) · Issue #2831 · matplotlib/matplotlib
Description: There is a discrepancy between vector format (pdf, svg, eps) output and image output (png, jpg, etc) for the BboxImage object. I can't attach a pdf, but the this code creates and saves a pdf and png illustrating the BboxImage object tran...
Open Graph Description: There is a discrepancy between vector format (pdf, svg, eps) output and image output (png, jpg, etc) for the BboxImage object. I can't attach a pdf, but the this code creates and saves a pdf and pn...
X Description: There is a discrepancy between vector format (pdf, svg, eps) output and image output (png, jpg, etc) for the BboxImage object. I can't attach a pdf, but the this code creates and saves a pdf an...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/2831
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug when saving to vector format (pdf, svg, eps)","articleBody":"There is a discrepancy between vector format (pdf, svg, eps) output and image output (png, jpg, etc) for the BboxImage object. I can't attach a pdf, but the this code creates and saves a pdf and png illustrating the BboxImage object translation. Just update the save folder path to run the code.\n\nThanks and let me know if I should include anything else.\n\n```\n'''\nMinimum working example\nversion 1.3.1\nPlots a descriptive flowchart showing error\n@Author: wronk\n'''\n\nfrom os import path as op\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nfrom matplotlib.image import BboxImage\nfrom matplotlib.offsetbox import TextArea, AnnotationBbox\nfrom matplotlib.transforms import Bbox\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\nfrom matplotlib.backends.backend_pdf import PdfPages\n\n###############################################################################\n#EDIT SAVE FOLDER TO AUTOSAVE\nsaveFig = True\nsave_fname = '/home/wronk/'\n\nmpl.rcParams['mathtext.default'] = 'rm'\n\n#Box properties\nbboxProp = dict(boxstyle='round,pad=0.3', fill=False, ec='w', linewidth=8)\n\n#Colors for annotation arrows\nsenCol = (0.35, 0.35, 0.35)\nsrcCol = (.8, .216, 0.0)\n\n#Define color map\ncm = 'autumn'\ncolRange = np.atleast_2d(np.arange(256)/256.)\n\n###############################################################################\n#Initialize Plot\nplt.ion()\nplt.close('all')\nmpl.rcParams['pdf.fonttype'] = 42\n\nfigSize = (12, 6)\nftSize = 32\ndpi = 80\nrowYVals = [0.085, 0.55, 0.85]\nrowXVals = [0, .075, .2, .34, .5, .65, .8, .875]\n\nfig = plt.figure(figsize=figSize, facecolor='white', dpi=dpi)\n#fig = plt.figure(figsize=figSize, facecolor='white')\n#ax = fig.gca()\nax = plt.subplot(111)\n\n###############################################################################\n#Mid level of annotation boxes\n#Text for boxes in mathematical font\nflowMid = r'$j_{N-1}$'\n\nmidBox3 = ax.annotate(flowMid, xy=(0, .5), xycoords='axes fraction',\n xytext=(rowXVals[3], rowYVals[1]),\n textcoords='axes fraction',\n size=ftSize, ha='left', va='center', bbox=bboxProp,\n arrowprops=None, color='black')\n\n#######################################\n#HEREIN LIES THE PROBLEM\n#Add color (gradients) behind the boxes\n\n#Something about the bbox window extent property must get shifted when saving\n#as a vector format (pdf, svg, eps) but not common image types. In my experience,\n#every bboximage was translated and scaled uniformly.\n\n#I tried changing DPI, image size, subplot parameters as well as sychronizing\n#plotting and saving figures in matplotlibrc to no avail. DPI does seem to\n#have some sort of effect in terms of how the bboximage gets shifted though.\n\ngradient = BboxImage(midBox3.get_bbox_patch().get_window_extent,\n data=np.zeros_like(colRange), cmap=cm, norm=None,\n origin=None)\nax.add_artist(gradient)\n\n#######################################\nplt.draw()\n\n#Save figure as pdf and png to highlight difference\n#Same results when saving from GUI window\nif saveFig:\n pdfFile = PdfPages(save_fname + 'flowchart_PDF.pdf')\n plt.savefig(pdfFile, format='pdf', dpi=fig.dpi)\n pdfFile.close()\n plt.savefig(save_fname + 'flowchart_PNG.png', dpi=fig.dpi)\nplt.show()\n```\n\n(tacaswell edited for code markup)\n","author":{"url":"https://github.com/wronk","@type":"Person","name":"wronk"},"datePublished":"2014-02-21T21:20:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":25},"url":"https://github.com/2831/matplotlib/issues/2831"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:34abf2b9-a8da-4f23-cf8a-588b9a423a80 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D450:1D5589:2B2835:3A0FB1:6A525A1B |
| html-safe-nonce | 4bdc6a21f47ccc6b3bb3163dcc3f8ec1ee9612faf5e2f52f6b0006a96b55103d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDUwOjFENTU4OToyQjI4MzU6M0EwRkIxOjZBNTI1QTFCIiwidmlzaXRvcl9pZCI6IjQ5MDE3MDI0MTEyNjgyODI5MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8b5ed364c2f7d7d6743afa0e5045bc7c338fcf1aa2e1bc83f5ef00a7f8e04d69 |
| hovercard-subject-tag | issue:28073966 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/2831/issue_layout |
| twitter:image | https://opengraph.githubassets.com/90b28751bb0a48b1b7b90c9c58e296aa244ca0b00fd5f24e0a096743421ddc02/matplotlib/matplotlib/issues/2831 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/90b28751bb0a48b1b7b90c9c58e296aa244ca0b00fd5f24e0a096743421ddc02/matplotlib/matplotlib/issues/2831 |
| og:image:alt | There is a discrepancy between vector format (pdf, svg, eps) output and image output (png, jpg, etc) for the BboxImage object. I can't attach a pdf, but the this code creates and saves a pdf and pn... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wronk |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width