Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Keep exact bitmap data when saving to vector file #16268

Copy link
Copy link
Open
@Synxis

Description

@Synxis
Issue body actions

I sometimes annotate plots using images (png format), and I want the image data not to be touched when saving to pdf: just put the data and the correct transformation in the pdf, if possible.
So instead of having a "fixed" dpi (which does not really make sense for vector formats anyway), passing something like dpi ='raw' (for example) would simply do what I explained before.

Even when explicitely adding resample = False, matplotlib still resample the image (I know this value is the default, but still). I don't know if this is a bug report or a feature request, I'm enclined to the former.

import numpy as np
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt

def add_image(axe, filename, position, zoom):
    img = plt.imread(filename)
    off_img = matplotlib.offsetbox.OffsetImage(img, zoom = zoom, resample = False)
    art = matplotlib.offsetbox.AnnotationBbox(off_img, position, xybox = (0, 0),
        xycoords = axe.transAxes, boxcoords = "offset points", frameon = False)
    axe.add_artist(art)

# ==========
fig = plt.figure()
axe = plt.axes()
fig.set_size_inches(3, 1.5)
axe.plot(np.arange(10), np.arange(10))

add_image(axe, "image.png", position = (0.2, 0.7), zoom = 0.07)

fig.savefig("temp.pdf", bbox_inches = "tight", pad_inches = 0)

Use it with this image from wikipedia as image.png.

Actual outcome (screenshot):

actual

Expected outcome (screenshot):

expected

Matplotlib:

  • Version: 3.1.2
  • Backend: PDF
  • Python: 3.7 64bit
  • Installed via: pip
  • OS: Windows 10

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actiontopic: images

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.