Every line of 'matlab add legend to plot' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
251 def legend(self, ax, lines=(), labels=(), legend_loc="best"): 252 ax.legend( 253 lines, 254 labels, 255 title=None, 256 loc=legend_loc, 257 frameon=False, 258 ncol=1, 259 labelspacing=0.5, 260 columnspacing=1, 261 borderpad=1, 262 handlelength=2, 263 fontsize=12, 264 ) 265 return ax
84 def tweak_legend(): 85 plt.gca().get_legend().texts[0].set_size("xx-small")
122 @staticmethod 123 def add_meta_scalability(legend, title: str = None): 124 125 plt.legend(legend, loc='lower right') 126 plt.xlabel("Nb of pictures [0-X]") 127 plt.ylabel("Time [s]") 128 129 if title is not None: 130 plt.title(title) 131 else: 132 plt.title("Performance measure depending on number of pictures in database")
198 def plotLegends(self): 199 if not self._legend:return 200 if not len(self._legendList):return 201 loc = (1.01, 0.0) 202 labelsep = 0.015 203 drawframe = True 204 fontproperties = FontProperties(size=10) 205 if len(self._legendList) > 14: 206 drawframe = False 207 if matplotlib_version < '0.99.0': 208 fontproperties = FontProperties(size=8) 209 loc = (1.05, -0.2) 210 else: 211 if len(self._legendList) < 18: 212 #drawframe = True 213 loc = (1.01, 0.0) 214 elif len(self._legendList) < 25: 215 loc = (1.05, 0.0) 216 fontproperties = FontProperties(size=8) 217 elif len(self._legendList) < 28: 218 loc = (1.05, 0.0) 219 fontproperties = FontProperties(size=6) 220 else: 221 loc = (1.05, -0.1) 222 fontproperties = FontProperties(size=6) 223 224 if matplotlib_version < '0.99.0': 225 legend = self.ax.legend(self._legendList, 226 loc = loc, 227 prop = fontproperties, 228 labelsep = labelsep, 229 pad = 0.15) 230 else: 231 legend = self.ax.legend(self._legendList, 232 loc = loc, 233 prop = fontproperties, 234 labelspacing = labelsep, 235 borderpad = 0.15) 236 legend.draw_frame(drawframe)
84 def add_to_canvas(self, ax, plots, legend=False, title=None, **kwargs): 85 #ax.autoscale_view() 86 fontdict=dict(family='sans-serif', weight='light', size=9) 87 if legend is True: 88 ax.legend(*ax.get_legend_handles_labels()) 89 elif legend >= 1: 90 #ax.legend(prop=fontdict) 91 legend_ontop(ax, ncol=legend, fontdict=fontdict) 92 if title is not None: ax.figure.suptitle(title) 93 return ax
312 def setLegends(self, legend, bylegend=None, byname=None, bytype=None, ct=0): 313 ct += 1 314 if isinstance(bylegend, str): 315 bylabel = [bylegend] 316 if isinstance(byname, str): 317 byname = [byname] 318 if isinstance(bytype, str): 319 bytype = [bytype] 320 321 if bylegend is None and byname is None and bytype is None: 322 if 'curve' in v: 323 bytype = all_curve_types 324 else: 325 bytype = all_point_types # Turn off all points 326 for k, v in self.items(): 327 if bytype is not None and isinstance(v, pargs) and (('curve' in v and v.type in bytype) or ('cycle' in v and k.strip('0123456789') in bytype)) or \ 328 byname is not None and k in byname or \ 329 bylegend is not None and isinstance(v, pargs) and (('curve' in v and v.curve[0].get_label() in bylegend) or ('cycle' in v and v.cycle[0].get_label() in bylegend)): 330 v.setLegend(legend, refresh=False) 331 elif isinstance(v, pargs): 332 v.setLegends(legend, bylegend=bylegend, byname=byname, bytype=bytype, ct=ct) 333 334 if ct == 1: 335 self.refresh()
916 def OnEnableLegend(self, event): 917 self.client.enableLegend = event.IsChecked()
194 def set_legend(self, legend: bool = True, legend_position: Optional[str] = "right"): 195 """Set the legend for plots. 196 197 Args: 198 legend: if having legend or not, default is True. 199 legend_position: the fontsize of the title, default is right. 200 """ 201 if legend: 202 self.opts["legendPosition"] = legend_position 203 else: 204 self.opts["legend"] = legend 205 return self
561 def legend(self, *args, **kwargs): 562 this_axes = self 563 class SmithHandlerLine2D(HandlerLine2D): 564 def create_artists(self, legend, orig_handle, 565 xdescent, ydescent, width, height, fontsize, 566 trans): 567 legline, legline_marker = HandlerLine2D.create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans) 568 569 if hasattr(orig_handle, "_markerhacked"): 570 this_axes._hack_linedraw(legline_marker, True) 571 return [legline, legline_marker] 572 return Axes.legend(self, *args, handler_map={Line2D : SmithHandlerLine2D()}, **kwargs)
516 def create_categorical_legend(colormap, aliases=None, font_size=10): 517 ''' 518 Creates a bokeh plot object with circle legend 519 swatches and text corresponding to the ``colormap`` key values 520 or the optional aliases values. 521 522 Parameters 523 ---------- 524 colormap : dict 525 Dictionary of category value to color value 526 527 aliases : dict 528 Dictionary of category value to aliases name 529 530 font_size: int 531 Font size to use in the legend text 532 ''' 533 y_max = font_size * 2 * len(colormap) 534 535 plot_options = {} 536 plot_options['x_range'] = Range1d(start=0, end=200) 537 plot_options['y_range'] = Range1d(start=0, end=y_max) 538 plot_options['plot_height'] = y_max + 2 * font_size 539 plot_options['plot_width'] = 190 540 plot_options['min_border_bottom'] = 0 541 plot_options['min_border_left'] = 0 542 plot_options['min_border_right'] = 0 543 plot_options['min_border_top'] = 0 544 plot_options['outline_line_width'] = 0 545 plot_options['toolbar_location'] = None 546 547 legend = Plot(**plot_options) 548 549 for i, (cat, color) in enumerate(colormap.items()): 550 text_y = y_max - font_size/2 - i * font_size * 2 551 text_val = aliases[cat] if aliases else cat 552 legend.add_glyph(Text(x=40, 553 y=text_y-font_size*1.2, 554 text=[text_val], 555 text_font_size='{}pt'.format(font_size), 556 text_color='#666666')) 557 558 legend.add_glyph(Circle(x=15, 559 y=text_y-font_size/2, 560 fill_color=color, 561 size=font_size, 562 line_color=None, 563 fill_alpha=0.8)) 564 565 return legend