8 examples of 'matplotlib legend size' in Python

Every line of 'matplotlib legend size' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
34def size_legend(size):
35 return plt.Line2D([0],[0], color='black', marker='o', linestyle='None', markersize=size**.5)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

325def legend(*args, **kwargs):
326 kwargs.setdefault('framealpha', 0.2)
327 try:
328 plt.legend(*args, **kwargs)
329 except:
330 warnings.warn("framealpha not effective")
331 kwargs.pop('framealpha')
332 plt.legend(*args, **kwargs)
251def 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
84def tweak_legend():
85 plt.gca().get_legend().texts[0].set_size("xx-small")
415def figlegend(handles, labels, loc, **kwargs):
416 """
417 Place a legend in the figure.
418
419 *labels*
420 a sequence of strings
421
422 *handles*
423 a sequence of :class:`~matplotlib.lines.Line2D` or
424 :class:`~matplotlib.patches.Patch` instances
425
426 *loc*
427 can be a string or an integer specifying the legend
428 location
429
430 A :class:`matplotlib.legend.Legend` instance is returned.
431
432 Example::
433
434 figlegend( (line1, line2, line3),
435 ('label1', 'label2', 'label3'),
436 'upper right' )
437
438 .. seealso::
439
440 :func:`~matplotlib.pyplot.legend`
441
442 """
443 l = gcf().legend(handles, labels, loc, **kwargs)
444 draw_if_interactive()
445 return l
2589def _paint_colorbar_legend(ax, values, cmap, legend_kwargs):
2590 """
2591 Creates a legend and attaches it to the axis. Meant to be used when a ``legend=True`` parameter is passed.
2592
2593 Parameters
2594 ----------
2595 ax : matplotlib.Axes instance
2596 The ``matplotlib.Axes`` instance on which a legend is being painted.
2597 values : list
2598 A list of values being plotted. May be either a list of int types or a list of unique entities in the
2599 data column (e.g. as generated via ``numpy.unique(data)``. This parameter is meant to be the same as that
2600 returned by the ``_discrete_colorize`` method.
2601 cmap : ``matplotlib.cm`` instance
2602 The `matplotlib` colormap instance which will be used to colorize the legend entries. This should be the
2603 same one used for colorizing the plot's geometries.
2604 legend_kwargs : dict
2605 Keyword arguments which will be passed to the matplotlib legend instance on initialization. This parameter
2606 is provided to allow fine-tuning of legend placement at the top level of a plot method, as legends are very
2607 finicky.
2608
2609 Returns
2610 -------
2611 None.
2612 """
2613 if not legend_kwargs: legend_kwargs = dict()
2614 cmap.set_array(values)
2615 plt.gcf().colorbar(cmap, ax=ax, **legend_kwargs)
561def 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)
198def 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)

Related snippets