Commit dfb2b8c437934fb6b46c818f9ba712f24fc54f3e
1 parent
5f703f7f
Adapt code to handle various matplotlib versions
Showing
1 changed file
with
18 additions
and
7 deletions
cscripts/csfootprint.py
| ... | ... | @@ -21,6 +21,7 @@ |
| 21 | 21 | import os |
| 22 | 22 | import pwd |
| 23 | 23 | import sys |
| 24 | +import inspect | |
| 24 | 25 | import gammalib |
| 25 | 26 | import ctools |
| 26 | 27 | |
| ... | ... | @@ -625,9 +626,12 @@ class csfootprint(ctools.cscript): |
| 625 | 626 | self._plot_daily(ax4, statistics, quantity='calls', |
| 626 | 627 | title='ctools calls', ylabel='calls') |
| 627 | 628 | |
| 629 | + # Kludge to adapt pie plotting to matplotlib version | |
| 630 | + args, _, _, _ = inspect.getargspec(plt.pie) | |
| 631 | + | |
| 628 | 632 | # Plot pie figures |
| 629 | - self._plot_pie(ax10, statistics, quantity='gCO2e', title='Footprint') | |
| 630 | - self._plot_pie(ax11, statistics, quantity='calls', title='ctools calls') | |
| 633 | + self._plot_pie(ax10, statistics, quantity='gCO2e', title='Footprint', args=args) | |
| 634 | + self._plot_pie(ax11, statistics, quantity='calls', title='ctools calls', args=args) | |
| 631 | 635 | |
| 632 | 636 | # Derive summary information from statistics |
| 633 | 637 | info = self._get_global_information(statistics, latex=True) |
| ... | ... | @@ -659,7 +663,8 @@ class csfootprint(ctools.cscript): |
| 659 | 663 | fig.text(x0, y0, 'Expected annual footprint: ', fontsize=fontsize, ha='left') |
| 660 | 664 | fig.text(x0+dx, y0, info['fp_yr'], fontsize=fontsize, ha='left') |
| 661 | 665 | |
| 662 | - plt.show() | |
| 666 | + # Optionally display figure for debugging | |
| 667 | + #plt.show() | |
| 663 | 668 | |
| 664 | 669 | # Save figure |
| 665 | 670 | fig.savefig(outfile, dpi=300) |
| ... | ... | @@ -713,7 +718,7 @@ class csfootprint(ctools.cscript): |
| 713 | 718 | return |
| 714 | 719 | |
| 715 | 720 | # Plot pie figure |
| 716 | - def _plot_pie(self, ax, statistics, quantity='gCO2e', title='Footprint', num=5): | |
| 721 | + def _plot_pie(self, ax, statistics, quantity='gCO2e', title='Footprint', num=5, args=None): | |
| 717 | 722 | """ |
| 718 | 723 | Plot pie figure |
| 719 | 724 | |
| ... | ... | @@ -729,6 +734,8 @@ class csfootprint(ctools.cscript): |
| 729 | 734 | Plot title |
| 730 | 735 | num : integer, optional |
| 731 | 736 | Number of pies displayed explicitly |
| 737 | + arg : list or str, optional | |
| 738 | + List of pie method keyword arguments | |
| 732 | 739 | """ |
| 733 | 740 | # Get Python version information |
| 734 | 741 | req_version = (2,4) |
| ... | ... | @@ -754,9 +761,13 @@ class csfootprint(ctools.cscript): |
| 754 | 761 | sizes.append(others) |
| 755 | 762 | |
| 756 | 763 | # Plot pie chart |
| 757 | - wedges, _, _ = ax.pie(sizes, autopct='%1.0f%%', pctdistance=0.8, | |
| 758 | - startangle=90, radius=1.0, | |
| 759 | - wedgeprops=dict(width=0.4, edgecolor='w')) | |
| 764 | + if 'wedgeprops' in args: | |
| 765 | + wedges, _, _ = ax.pie(sizes, autopct='%1.0f%%', pctdistance=0.8, | |
| 766 | + startangle=90, radius=1.0, | |
| 767 | + wedgeprops=dict(width=0.4, edgecolor='w')) | |
| 768 | + else: | |
| 769 | + wedges, _, _ = ax.pie(sizes, autopct='%1.0f%%', pctdistance=0.8, | |
| 770 | + startangle=90, radius=1.0) | |
| 760 | 771 | ax.axis('equal') |
| 761 | 772 | ax.legend(wedges, labels, loc='center', fontsize=8, frameon=False) |
| 762 | 773 | ... | ... |