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

Skip to content

Non-accurate placing of images from plt.imshow in PDF output #2935

@mojca

Description

@mojca

I have some problems with non-accurate placing of images created by imshow. Output to PNG works fine, but the squares are rectangular and misaligned with the grid when plotting small squares to PDF (order of magnitude around 1-2 inches for the whole plot). I didn't inspect the contents of PDF, but I suspect that coordinates might be written with too low precision.

Here's a small example (maybe not the minimal possible, but hopefully short enough):

import numpy as np
import matplotlib.pyplot as plt

plt.gcf().set_size_inches([1,1])
a=np.random.rand(20,20)
im = plt.imshow(a, interpolation='nearest', origin='lower', extent=[-2,2,-2,2])
plt.gca().set_xticks(np.arange(-2,2,0.2))
plt.gca().set_yticks(np.arange(-2,2,0.2))
plt.gca().xaxis.set_ticklabels([])
plt.gca().yaxis.set_ticklabels([])
plt.grid(ls=':',lw=0.1,color='white')
plt.savefig('test.pdf')

x

I'm using python 3.3 and matplotlib 1.3.1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions