2

By this piece of code I'm generating multiple plots(PIE chats) in one pdf

import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

pp = PdfPages('long.pdf')

lists = [
    ([1, 3, 6], ["bells label", "whistles label", "pasta label"], 'title-1'), 
    ([11, 3, 6, 5], ["red colour", "blue colour", "green colour", "back colour"], 'title-2')
]

for x_list,label_list,title in lists:
    plt.figure(figsize=(2,2), dpi=100)
    # plt.axes([0.1, 0.1, 0.8, 0.8])
    plt.axis('equal')

    explode = [0.2]
    explode += [0 for x in range(len(x_list)-1)]

    plt.pie(x_list, labels=label_list, explode=explode, autopct="%1.1f%%", startangle=90)
    plt.title(title)
    plt.savefig(pp, format='pdf')
    # pp.savefig()

pp.close()

but I'm getting output like this, very unclear/overlapped/stripped.
How can I fix this ?

enter image description here

PS: I need your expertise in this library.
How can I improve this in looking/structure ?
Any suggestion would be appreciated.

joaquin
  • 82,968
  • 29
  • 138
  • 152
xyz
  • 197
  • 3
  • 16

1 Answers1

2

You need to use a text size compatible with your figure size.
Either you reduce text or increase figure size.
In addition, you can increase the pad of the sides (this reduces the space occupied by the figure and gives more place for the labels and titles.

For example:

for x_list,label_list,title in lists:
    figure(figsize=(4,4), dpi=100)                # increase figure size
    plt.axis('equal')
    subplots_adjust(left=0.3, right=0.6) # give more space to the borders
    explode = [0.2]
    explode += [0 for x in range(len(x_list)-1)]

    plt.pie(x_list, labels=label_list, explode=explode, autopct="%1.1f%%", startangle=90)
    plt.title(title)
    plt.savefig(pp, format='pdf')

pp.close()

This produces the pdf below (exported to png). I exaggerated the padding and the figure size. You should fine tune it for your needs.

enter image description here

joaquin
  • 82,968
  • 29
  • 138
  • 152
  • @xyz http://stackoverflow.com/questions/3899980/how-to-change-the-font-size-on-a-matplotlib-plot – joaquin Sep 20 '14 at 08:57