I have a figure with some pretty delicate features that are sensitive to line width. I want to save this figure as a PDF, which can be easily printed (i.e. do not scale on the receiver side, just Command + P and go). Unfortunately, when I set figsize = (8.5, 11) to correctly print the PDF for printing, matplotlib selects the very thick line width and text size that ruined the graph (the legend is too large and the lines in the overlap histogram). If I set figsize = (17,22), I get a very effective line width and text after scaling the PDF to 50% for printing. This is what I used, but this solution became unworkable due to the policy, and I really do not want to scale the PDF in Illustrator every time I make changes.
If I could work with bitmap images, I could achieve the desired result by setting figsize = (17,22) and setting dpi to half the target dpi, but this does not work for PDF files, since the dpi parameter seems to be ignored. I need a pdf which
- looks like box_good.png (bitmap with distorted size with thin lines, small text).
- measures 8.5x11in (or prints like it)
- can be edited in illustrator (this is not a bitmap wrapped in pdf)
I cannot help but suspect that when saving to PDF, there is an easy way to pull out the “double size, half-inch” trick, but I refused it to work, and started trying to directly manipulate the line widths and texts. I managed to change the text, but not the line width. Here is a record of what I tried:
# Tried:
Here is the source file (I shortened the schedule to the necessary items, so the obvious style workarounds are probably not workable solutions)
import numpy as np import matplotlib as mp import matplotlib.pyplot as plt x = np.arange(200) bottom_red_bar = -np.random.random(200) bottom_black_bar = np.random.random(200) * bottom_red_bar fig = plt.figure() for subplotnum in [1,2,3]: pax = plt.subplot(310+subplotnum) pax.set_ylim([-1,1]) bot_rb = pax.bar(x, bottom_red_bar,1,color='r') bot_bb = pax.bar(x+(1-.3)/2,bottom_black_bar,.3,color='k') pax.legend([bot_rb,bot_bb],['Filler Text 1','Filler Text 2'],loc=4) fig.set_size_inches(8.5,11) fig.savefig('boxes_bad.png',dpi=300)
Thus, I get the opportunity to adjust the line width for the whole figure or the way to have matplotlib to save pdf with dimension metadata other than figsize. Any suggestions?