Changeset 870
- Timestamp:
- 05/14/2007 11:33:29 AM (3 years ago)
- Files:
-
- GraphTool/examples/simple/quality_map.py (modified) (1 diff)
- GraphTool/examples/simple/quality_map_tall.py (added)
- GraphTool/src/graphtool/graphs/common_graphs.py (modified) (2 diffs)
- GraphTool/src/graphtool/graphs/graph.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
GraphTool/examples/simple/quality_map.py
r859 r870 15 15 return begin_time, end_time, data 16 16 17 QM = QualityMap() 17 18 18 # Bar graph stuff. 19 QM = QualityMap() 19 # Data generation 20 20 full_data = {} 21 21 for i in range(10): GraphTool/src/graphtool/graphs/common_graphs.py
r865 r870 759 759 return None 760 760 761 class QualityMap( TimeGraph, PivotGroupGraph ):761 class QualityMap( HorizontalGraph, TimeGraph, PivotGroupGraph ): 762 762 763 763 sort_keys = Graph.sort_keys … … 871 871 coords[link][timebin] = p 872 872 873 y_vals = numpy.arange(.5,len(links)+.5,1)874 fl = FixedLocator( y_vals )875 if self.kind.lower() == "link":876 links = [ i[0] + ' to ' + i[1] for i in links ]877 878 873 # Make the colorbar 879 cb = self.fig.colorbar( self.mapper, format="%d%%", orientation='horizontal', fraction=0.04, pad=0.13, aspect=40 ) 874 # Calculate padding 875 pad_pix = self.additional_vertical_padding() 876 height_inches = self.fig.get_size_inches()[-1] 877 pad_perc = pad_pix / self.fig.get_dpi() / height_inches / 2.0 878 print "pad perc", pad_perc 879 cb = self.fig.colorbar( self.mapper, format="%d%%", orientation='horizontal', fraction=0.04, pad=pad_perc, aspect=40 ) 880 880 setp( cb.outline, linewidth=.5 ) 881 881 setp( cb.ax.get_xticklabels(), size=10 ) 882 882 setp( cb.ax.get_xticklabels(), family=self.prefs['font_family'] ) 883 883 setp( cb.ax.get_xticklabels(), fontname = self.prefs['font'] ) 884 885 # Make the formatter for the y-axis 886 ff = FixedFormatter( links ) 887 ax.yaxis.set_major_formatter( ff ) 888 ax.yaxis.set_major_locator( fl ) 889 890 # Calculate the spacing of the y-tick labels: 891 height_per = ax.get_position()[-1] 892 height_inches = self.fig.get_size_inches()[-1] * height_per 893 height_pixels = self.fig.get_dpi() * height_inches 894 max_height_labels = height_pixels / max( 1, len(links) ) 895 896 # Adjust the font height to match the maximum available height 897 font_height = max_height_labels * 1.7 / 3.0 - 1.0 898 font_height = min( font_height, 7 ) 899 setp( ax.get_yticklabels(), size=font_height ) 900 901 ax.yaxis.draw( self.canvas.get_renderer() ) 902 903 total_xmax = 0 904 for label in ax.get_yticklabels(): 905 bbox = label.get_window_extent( self.canvas.get_renderer() ) 906 total_xmax = max( bbox.xmax()-bbox.xmin(), total_xmax ) 907 move_left = (total_xmax+6) / self.prefs['width'] 908 pos = ax.get_position() 909 pos[0] = move_left 910 pos[2] = 1 - pos[0] - .02 911 ax.set_position( pos ) 884 885 def additional_vertical_padding(self): 886 return 120 912 887 913 888 def get_coords( self ): GraphTool/src/graphtool/graphs/graph.py
r869 r870 6 6 from matplotlib.backends.backend_svg import FigureCanvasSVG 7 7 from matplotlib.figure import Figure 8 from matplotlib.ticker import FixedLocator 8 from matplotlib.ticker import FixedLocator, FixedFormatter 9 9 from matplotlib.backends.backend_svg import RendererSVG 10 10 from matplotlib.patches import Wedge, Shadow, Rectangle, Polygon … … 22 22 'text_padding' : 3, #in pixels 23 23 'legend_padding' : .01, # In percent of screen space / 100 24 'figure_padding' : .10,24 'figure_padding' : 50, #in pixels 25 25 'width' : 800, #in pixels 26 26 'height' : 500, … … 35 35 'square_axis' : False, 36 36 'watermark' : '$GRAPHTOOL_ROOT/static_content/CMSbwl3.png', 37 'fixed-height' : True 37 38 } 38 39 … … 267 268 height_inches = prefs['height'] / dpi 268 269 270 # Conversion from pixels to percentage of screen 271 figure_padding_perc = prefs['figure_padding'] / float(prefs['height']) 272 269 273 # Calculations for the legend 270 274 rows = 0.0; column_height = 0.0; bottom = 0.0 … … 296 300 legend_rect = prefs['legend_padding'], prefs['legend_padding'], legend_width, legend_height 297 301 if prefs['square_axis']: 298 min_size = min( 1 - 1.5* prefs['figure_padding'], 1 - bottom - 2*prefs['figure_padding'])302 min_size = min( 1 - 1.5*figure_padding_perc, 1 - bottom - 2*figure_padding_perc ) 299 303 ax_rect = (.5 - min_size/2.0*prefs['height']/float(prefs['width']), 300 prefs['figure_padding']+ bottom,304 figure_padding_perc + bottom, 301 305 prefs['height']/float(prefs['width'])*min_size, 302 306 min_size ) 303 307 else: 304 ax_rect = ( prefs['figure_padding'],305 prefs['figure_padding']+ bottom,306 1 - 1.5* prefs['figure_padding'],307 1 - bottom - 2* prefs['figure_padding'])308 ax_rect = (figure_padding_perc, 309 figure_padding_perc + bottom, 310 1 - 1.5*figure_padding_perc, 311 1 - bottom - 2*figure_padding_perc) 308 312 309 313 # Add a watermark: … … 345 349 # Creates a subtitle, if necessary 346 350 title = title.split('\n',1) 347 if len(title) == 1: 348 ax.set_title( title[0] ) 349 else: 350 ax.set_title( title[0] + '\n' ) 351 subtitle_height_pix = (prefs['subtitle_size'] + 2*prefs['text_padding']) * (len(title) > 1) 352 ax_height_pix = ax_rect[-1] * height_inches * dpi 353 print "ax_height_pix", ax_height_pix 354 ax.title = ax.text( 0.5, 1 + (subtitle_height_pix + prefs['text_padding'])/ax_height_pix, title[0], 355 verticalalignment='bottom', horizontalalignment='center' ) 356 if len(title) > 1: 351 357 ax.title.set_transform( ax.transAxes ) 352 358 ax.title.set_clip_box( None ) 353 359 ax._set_artist_props( ax.title ) 354 ax.subtitle = ax.text( 0.5, 1.0 2, title[1],360 ax.subtitle = ax.text( 0.5, 1.0 + prefs['text_padding']/ax_height_pix, title[1], 355 361 verticalalignment='bottom', 356 362 horizontalalignment='center' ) … … 463 469 # First, prepare the canvas to calculate all the necessary parts. 464 470 super( HorizontalGraph, self ).prepare_canvas() 465 if self.prefs ['fixed']== False:471 if self.prefs.get('fixed-height',True) == False: 466 472 # Then, we re-calculate the heights based on number of labels. 467 473 labels = getattr( self, 'labels', [] ) 468 474 height = self.ax.get_position()[3] 469 dpi = self.fig ure.get_dpi()470 fig_width, fig_height = self.fig ure.get_size_inches()475 dpi = self.fig.get_dpi() 476 fig_width, fig_height = self.fig.get_size_inches() 471 477 height_pix = height * fig_height * dpi 472 478 num_labels = len(labels) 473 479 pixels_per_label = 2*self.prefs['text_padding'] + self.prefs['text_size'] 474 new_height_pix = max(num_labels * pixels_per_label, height_pix) 475 prefs['height'] += new_height_pix - height_pix 476 480 print pixels_per_label 481 new_height_pix = max(num_labels * pixels_per_label + 2*self.prefs['figure_padding'], height_pix) 482 self.metadata['height'] = self.prefs['height'] + new_height_pix - height_pix + self.additional_vertical_padding() 483 print self.metadata['height'] 484 self.metadata['fixed-height'] = True 477 485 # After we calculate the new height, prepare the canvas again. 478 486 super( HorizontalGraph, self ).prepare_canvas() … … 480 488 def y_formatter_cb(self, ax): 481 489 # y_vals should be the y-location of the labels. 490 labels = getattr( self, 'labels', [] ) 482 491 y_vals = numpy.arange(.5,len(labels)+.5,1) 483 492 … … 489 498 ax.yaxis.set_major_locator( fl ) 490 499 500 def additional_vertical_padding(self): return 0 491 501 492 502 def write_graph(self): 493 503 # Calculate the spacing of the y-tick labels: 494 height_per = ax.get_position()[-1] 504 labels = getattr( self, 'labels', [] ) 505 height_per = self.ax.get_position()[-1] 495 506 height_inches = self.fig.get_size_inches()[-1] * height_per 496 507 height_pixels = self.fig.get_dpi() * height_inches 497 max_height_labels = height_pixels / max( 1, len(links) ) 508 print "height_pixels", height_pixels, height_per 509 max_height_labels = height_pixels / max( 1, len(labels) ) 510 print max_height_labels 498 511 499 512 # Adjust the font height to match the maximum available height 500 513 font_height = max_height_labels * 1.7 / 3.0 - 1.0 501 514 font_height = min( font_height, 7 ) 502 setp( ax.get_yticklabels(), size=font_height )503 504 ax.yaxis.draw( self.canvas.get_renderer() )515 setp( self.ax.get_yticklabels(), size=font_height ) 516 517 self.ax.yaxis.draw( self.canvas.get_renderer() ) 505 518 506 519 total_xmax = 0 507 for label in ax.get_yticklabels():520 for label in self.ax.get_yticklabels(): 508 521 bbox = label.get_window_extent( self.canvas.get_renderer() ) 509 522 total_xmax = max( bbox.xmax()-bbox.xmin(), total_xmax ) 510 523 move_left = (total_xmax+6) / self.prefs['width'] 511 524 512 pos = ax.get_position()525 pos = self.ax.get_position() 513 526 pos[0] = move_left 514 527 pos[2] = 1 - pos[0] - .02 515 ax.set_position( pos ) 528 self.ax.set_position( pos ) 529 530 # Finally, call normal writer. 531 super( HorizontalGraph, self ).write_graph() 516 532 517 533 class DBGraph( Graph ):
