Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phantom axis in eps images despite having set invisible axis in matplotlib #2580

Closed
nye17 opened this issue Nov 6, 2013 · 1 comment
Closed

Comments

@nye17
Copy link

nye17 commented Nov 6, 2013

This is a replicate of a question I posted on stackoverflow, where you can find the screenshots of the two figure file I mentioned below.

http://stackoverflow.com/questions/19761335/phantom-axis-in-eps-images-despite-having-set-invisible-axis-in-matplotlib

I managed to put those line in my matplotlib code

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)

in hopes of hiding the top, right, and left axes in the saved images. They worked fine in png images, but in the saved eps files, there are still boundaries (not sure whether they are axes) on the left and the top (the right axis indeed disappeared).

I just did several tests with the following minimal working example, it turns out the axes will be invisible even in eps outputs if I either 1) turn off rasterization in eps; or 2) turn off manual settings on xticks and xticklabels

However, both above features are what I absolutely need to keep in the eps output, so, any solutions?

Matplotlib version: 1.3.1, python 2.7.5, under Debian Jesse.

import matplotlib.pyplot as plt
import numpy as np
# setting up fig and ax
fig = plt.figure(figsize=(12,6))
ax  = fig.add_axes([0.00,0.10,0.90,0.90])
# translucent vertical band as the only subject in the figure
# note the zorder argument used here
ax.axvspan(2014.8, 2017.8, color="DarkGoldenRod", alpha=0.3, zorder=-1)
# setting up axes
ax.set_xlim(2008, 2030)
ax.set_ylim(-2, 2)
# if you toggle this to False, the axes are hidden
if True :
    # manually setting ticks
    ticks = np.arange(2008, 2030, 2)
    ax.set_xticks(ticks)
    ax.set_xticklabels([r"$\mathrm{" + str(r) + r"}$" for r in ticks], fontsize=26, rotation=30)
    ax.get_xaxis().tick_bottom()
    ax.set_yticks([]) 
# hide all except for the bottom axes
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
# if you toggle this to False, the axes are hidden
if True :
    # this is to make sure the rasterization works.
    ax.set_rasterization_zorder(0)
# save into eps and png separately
fig.savefig("test.eps", papertype="a4", format="eps", bbox_inches='tight', pad_inches=0.1, dpi=None)
fig.savefig("test.png", papertype="a4", format="png", bbox_inches='tight', pad_inches=0.1, dpi=None)
@tacaswell
Copy link
Member

This was resolved by #2479

The problem is that the default color for the empty canvas in AGG was (0, 0, 0, 0) (fully transparent black) but eps does not handle alpha (it just gets dropped) so (0,0,0,0) -> (0,0,0) when shoved into an eps file. If you turn the axes off, that region of the canvas is never drawn too, hence it stays the default color. The accepted answer on SO forces those pixels to get rendered (and composited onto a white background) so you don't see the black line in the eps file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants