You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
phantom axis in eps images despite having set invisible axis in matplotlib #2580
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)
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.
Activity
tacaswell commentedon Nov 26, 2014
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.