当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasAgg.mpl_connect方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_agg.FigureCanvasAgg.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasAgg.mpl_connect方法的具体用法?Python FigureCanvasAgg.mpl_connect怎么用?Python FigureCanvasAgg.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_agg.FigureCanvasAgg的用法示例。


在下文中一共展示了FigureCanvasAgg.mpl_connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: view

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import mpl_connect [as 别名]
  def view(self, fig, id=None, small_ticks=True):
    """ fig is a matplotlib figure, which can be created using methods
    in the axes module (or using matplotlib). It is possible to give
    and id to the figure, and then refer to this id when attaching an 
    areaselect widget to the Figure.
    """
    if small_ticks:
      for ax in fig.get_axes():
        axes.small_ticks(ax)
    if not id:
      id = self._get_unique_id()
    image_filename = '%s.png' % id
    full_filename = os.path.join(settings.FREECELL_DIR, 'temp', image_filename)
    
    def on_draw(event):
      fig = event.canvas.figure
      ax = fig.axes[0]
      self.data_point1 = (0,0)
      self.data_point2 = (1,1)
      # The conversion between pixels and data is linear, so we try to get 
      # the line parameters. This has to be done in the draw event of the print.
      # (Otherwise the transData misbehaves)
      self.pixel_point1 = ax.transData.transform(self.data_point1)
      self.pixel_point2 = ax.transData.transform(self.data_point2)

      
    canvas = FigureCanvasAgg(fig)
    canvas.mpl_connect('draw_event', on_draw)
    canvas.print_figure(full_filename, dpi=DPI)
    
    data = {}
    # The values calculated here are of the linear formula used to convert pixel to data point and vice versa.
    # This is used by AreaSelect.
    data['a_pixel_x'], data['b_pixel_x'] = get_line_parameters(self.data_point1[0], self.pixel_point1[0], self.data_point2[0], self.pixel_point2[0])
    data['a_pixel_y'], data['b_pixel_y'] = get_line_parameters(self.data_point1[1], self.pixel_point1[1], self.data_point2[1], self.pixel_point2[1])
    data['a_data_x'], data['b_data_x'] = get_line_parameters(self.pixel_point1[0], self.data_point1[0], self.pixel_point2[0], self.data_point2[0])
    data['a_data_y'], data['b_data_y'] = get_line_parameters(self.pixel_point1[1], self.data_point1[1], self.pixel_point2[1], self.data_point2[1])
    data['pixel_width'] = fig.get_size_inches()[0] * DPI
    data['pixel_height'] = fig.get_size_inches()[1] * DPI
    data['id'] = id
    data['id_function'] = id.replace('-','_')
    html = render('figure.html', data)

    with open(full_filename, 'rb') as f:
      imgdata = f.read()     
     
    return View(
      self,
      html,
      [],
      [],
      {image_filename : imgdata})
开发者ID:ericjsolis,项目名称:danapeerlab,代码行数:54,代码来源:figure.py


注:本文中的matplotlib.backends.backend_agg.FigureCanvasAgg.mpl_connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。