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,6 +21,7 @@ | ||
| 21 | import os | 21 | import os |
| 22 | import pwd | 22 | import pwd |
| 23 | import sys | 23 | import sys |
| 24 | +import inspect | ||
| 24 | import gammalib | 25 | import gammalib |
| 25 | import ctools | 26 | import ctools |
| 26 | 27 | ||
| @@ -625,9 +626,12 @@ class csfootprint(ctools.cscript): | @@ -625,9 +626,12 @@ class csfootprint(ctools.cscript): | ||
| 625 | self._plot_daily(ax4, statistics, quantity='calls', | 626 | self._plot_daily(ax4, statistics, quantity='calls', |
| 626 | title='ctools calls', ylabel='calls') | 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 | # Plot pie figures | 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 | # Derive summary information from statistics | 636 | # Derive summary information from statistics |
| 633 | info = self._get_global_information(statistics, latex=True) | 637 | info = self._get_global_information(statistics, latex=True) |
| @@ -659,7 +663,8 @@ class csfootprint(ctools.cscript): | @@ -659,7 +663,8 @@ class csfootprint(ctools.cscript): | ||
| 659 | fig.text(x0, y0, 'Expected annual footprint: ', fontsize=fontsize, ha='left') | 663 | fig.text(x0, y0, 'Expected annual footprint: ', fontsize=fontsize, ha='left') |
| 660 | fig.text(x0+dx, y0, info['fp_yr'], fontsize=fontsize, ha='left') | 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 | # Save figure | 669 | # Save figure |
| 665 | fig.savefig(outfile, dpi=300) | 670 | fig.savefig(outfile, dpi=300) |
| @@ -713,7 +718,7 @@ class csfootprint(ctools.cscript): | @@ -713,7 +718,7 @@ class csfootprint(ctools.cscript): | ||
| 713 | return | 718 | return |
| 714 | 719 | ||
| 715 | # Plot pie figure | 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 | Plot pie figure | 723 | Plot pie figure |
| 719 | 724 | ||
| @@ -729,6 +734,8 @@ class csfootprint(ctools.cscript): | @@ -729,6 +734,8 @@ class csfootprint(ctools.cscript): | ||
| 729 | Plot title | 734 | Plot title |
| 730 | num : integer, optional | 735 | num : integer, optional |
| 731 | Number of pies displayed explicitly | 736 | Number of pies displayed explicitly |
| 737 | + arg : list or str, optional | ||
| 738 | + List of pie method keyword arguments | ||
| 732 | """ | 739 | """ |
| 733 | # Get Python version information | 740 | # Get Python version information |
| 734 | req_version = (2,4) | 741 | req_version = (2,4) |
| @@ -754,9 +761,13 @@ class csfootprint(ctools.cscript): | @@ -754,9 +761,13 @@ class csfootprint(ctools.cscript): | ||
| 754 | sizes.append(others) | 761 | sizes.append(others) |
| 755 | 762 | ||
| 756 | # Plot pie chart | 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 | ax.axis('equal') | 771 | ax.axis('equal') |
| 761 | ax.legend(wedges, labels, loc='center', fontsize=8, frameon=False) | 772 | ax.legend(wedges, labels, loc='center', fontsize=8, frameon=False) |
| 762 | 773 |