plugin.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:matplotlib 作者: DaveL17 项目源码 文件源码
def chartMultilineText(self, dev, p_dict, k_dict, text_to_plot, return_queue):
        """"""

        log = {'Threaddebug': [], 'Debug': [], 'Info': [], 'Warning': [], 'Critical': []}
        try:

            import textwrap

            if self.verboseLogging:
                log['Debug'].append(u"{0:<19}{1}".format("p_dict: ", [(k, v) for (k, v) in sorted(p_dict.items())]))
                log['Debug'].append(u"{0:<19}{1}".format("k_dict: ", [(k, v) for (k, v) in sorted(k_dict.items())]))

            p_dict['textColor'] = r"#{0}".format(p_dict['textColor'].replace(' ', '').replace('#', ''))

            # If the value to be plotted is empty, use the default text from the device configuration.
            if len(text_to_plot) <= 1:
                text_to_plot = unicode(p_dict['defaultText'])
            else:
                # The cleanUpString method tries to remove some potential ugliness from the text to be plotted. It's optional--defaulted to on. No need to call this if the default text
                # is used.
                if p_dict['cleanTheText']:
                    text_to_plot = self.cleanUpString(text_to_plot)

            # Wrap the text and prepare it for plotting.
            text_to_plot = textwrap.fill(text_to_plot, int(p_dict['numberOfCharacters']), replace_whitespace=p_dict['cleanTheText'])

            ax = self.chartMakeFigure(p_dict['figureWidth'], p_dict['figureHeight'], p_dict)

            ax.text(0.01, 0.95, text_to_plot, transform=ax.transAxes, color=p_dict['textColor'], fontname=p_dict['fontMain'], fontsize=p_dict['multilineFontSize'],
                    verticalalignment='top')

            ax.axes.get_xaxis().set_visible(False)
            ax.axes.get_yaxis().set_visible(False)

            if not p_dict['textAreaBorder']:
                [s.set_visible(False) for s in ax.spines.values()]

            # Transparent Charts Fill
            if p_dict['transparent_charts'] and p_dict['transparent_filled']:
                ax.add_patch(patches.Rectangle((0, 0), 1, 1, transform=ax.transAxes, facecolor=p_dict['faceColor'], zorder=1))

            # Chart title
            plt.title(p_dict['chartTitle'], position=(0.5, 1.0), **k_dict['k_title_font'])

            plt.tight_layout(pad=1)
            plt.subplots_adjust(left=0.02, right=0.98, top=0.9, bottom=0.05)

            if p_dict['fileName'] != '':
                plt.savefig(u'{0}{1}'.format(p_dict['chartPath'], p_dict['fileName']), **k_dict['k_plot_fig'])

            plt.clf()
            plt.close('all')

            return_queue.put({'Error': False, 'Log': log, 'Message': 'updated successfully.', 'Name': dev.name})

        except (KeyError, IndexError, ValueError, UnicodeEncodeError) as sub_error:
            return_queue.put({'Error': True, 'Log': log, 'Message': str(sub_error), 'Name': dev.name})
        except Exception as sub_error:
            return_queue.put({'Error': True, 'Log': log, 'Message': str(sub_error), 'Name': dev.name})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号