Description
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.
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)