当前位置: 首页 > news >正文

做家乡的网站网址推广

做家乡的网站,网址推广,广州网站建设 乐云seo,免费数据库网站我们将图例进行行显示或者列显示后,只能想继续赋予不同行或者列不同的title来进行分类。比较简单的方式,就是通过ax.annotate方法添加标签,这样方法复用率比较低,每次使用都要微调ax.annotate的显示位置。比较方便的方法是在案例1…

我们将图例进行行显示或者列显示后,只能想继续赋予不同行或者列不同的title来进行分类。比较简单的方式,就是通过ax.annotate方法添加标签,这样方法复用率比较低,每次使用都要微调ax.annotate的显示位置。比较方便的方法是在案例1实现的基础上,添加title显示的功能。

motplotlib图例案例1:通过多个legend完全控制图例显示顺序(指定按行排序 or 按列排序)

添加title显示功能后的代码:

import matplotlib.pyplot as plt
import matplotlib.axes
from typing import List, Tuple, Any
#这个函数可以获得axis对象的已经绘制的artist中的所有的hander和labels,这个可以只给它一个axis参数。注意这个参数需要是列表类的。
from matplotlib.legend import _get_legend_handles_labels as get_legend_handles_labelsdef custom_legend_layout(axis: matplotlib.axes.Axes,handlers: List[Any]=None,labels: List[str]=None,n_items: int = 3,offset: float = 0.05,vertical: bool = False,loc: str = 'upper right',first_bbox_to_anchor: Tuple[float, float] = (1, 1),title:List[str]=None,title_shift:List[Tuple[float,float]]=None,**kwargs) -> None:"""A function to arrange legend items in a custom layout.:param axis: Axis object on which to place the legends.:param lines: List of line objects to include in the legends.:param labels: List of labels corresponding to the line objects.:param n_items: Number of items per row (if vertical=False) or column (if vertical=True).:param offset: Vertical offset between rows (or horizontal offset between columns if vertical=True).:param vertical: If True, legends are arranged vertically, otherwise horizontally.:param loc: Location anchor for all legends.:param first_bbox_to_anchor:  `~matplotlib.transforms.BboxBase` instance,Bbox anchor of the first legend.:param kwargs: Additional keyword arguments to pass to the legend function."""va_dict={"center":'center',"lower":'top',"upper":'bottom'}ha_dict={"center": 'center',"right":"left","left":"right",}if (handlers is None) != (labels is None):  # Check if only one of handlers or labels is providedraise ValueError("Both 'handlers' and 'labels' must be specified if one is provided.")if (handlers is None) and (labels is None): # get default handlers and labels from axhandlers,labels=get_legend_handles_labels(axs=[axis]) # note:  the param axs is list object# 确保n_items不为0,避免除以0的错误n_items = max(1, n_items)# 计算需要多少个图例n_legends = len(handlers) // n_items + (1 if len(handlers) % n_items else 0)# 计算每个图例的bbox_to_anchorfor i in range(n_legends):start_idx = i * n_itemsend_idx = min(start_idx + n_items, len(handlers))legend_lines = handlers[start_idx:end_idx]legend_labels = labels[start_idx:end_idx]if vertical:# 对于垂直布局ncol = 1if i == 0:bbox_anchor = first_bbox_to_anchorelse:# 计算后续图例的bbox_to_anchorbbox_anchor = (first_bbox_to_anchor[0] + i * offset, first_bbox_to_anchor[1])else:# 对于水平布局ncol = len(legend_lines)if i == 0:bbox_anchor = first_bbox_to_anchorelse:# 计算后续图例的bbox_to_anchorbbox_anchor = (first_bbox_to_anchor[0], first_bbox_to_anchor[1] - i * offset)legend = axis.legend(legend_lines, legend_labels, loc=loc, bbox_to_anchor=bbox_anchor, ncol=ncol, frameon=False, **kwargs)axis.add_artist(legend)# 计算每个title的位置va_key,ha_key=loc.split(" ")if title and len(title)==n_legends:w_shift= title_shift[i][0] if title_shift else 0h_shift=title_shift[i][1] if title_shift else 0axis.annotate(text=title[i],xy=(bbox_anchor[0]+w_shift, bbox_anchor[1]+h_shift),xycoords='axes fraction',va=va_dict[va_key],ha=ha_dict[ha_key])if __name__ == '__main__':# 示例使用这个函数fig, ax = plt.subplots()handlers = [ax.scatter(range(10), [i * x for x in range(10)], label=f'Line {i}') for i in range(7)]# 调用函数,横向排列图例custom_legend_layout(ax, n_items=3, offset=0.25, vertical=True,loc='upper left', first_bbox_to_anchor=(0.2, 0.8),title=["title 1","title 2","title 3"],#title_shift=[(-0.1,0),(-0.1,0),(-0.1,0)],)from matplotlib.legend import _get_legend_handles_labels as get_legend_handles_labelshandles,labels=get_legend_handles_labels([ax])plt.show()

运行后:

在这里插入图片描述


文章转载自:
http://quadratic.tzmc.cn
http://micropuncture.tzmc.cn
http://acquit.tzmc.cn
http://disanoint.tzmc.cn
http://violin.tzmc.cn
http://shammy.tzmc.cn
http://kharkov.tzmc.cn
http://rut.tzmc.cn
http://redskin.tzmc.cn
http://pioupiou.tzmc.cn
http://emigre.tzmc.cn
http://hareem.tzmc.cn
http://reflecting.tzmc.cn
http://radiopharmaceutical.tzmc.cn
http://bumper.tzmc.cn
http://interruptedly.tzmc.cn
http://pigsty.tzmc.cn
http://torturous.tzmc.cn
http://victimization.tzmc.cn
http://ossuarium.tzmc.cn
http://disability.tzmc.cn
http://cornily.tzmc.cn
http://kinship.tzmc.cn
http://mig.tzmc.cn
http://deodorise.tzmc.cn
http://easement.tzmc.cn
http://minstrel.tzmc.cn
http://syngas.tzmc.cn
http://polysyntheticism.tzmc.cn
http://inexplainably.tzmc.cn
http://fishery.tzmc.cn
http://seasonable.tzmc.cn
http://xeroma.tzmc.cn
http://elasticizer.tzmc.cn
http://cenobian.tzmc.cn
http://description.tzmc.cn
http://align.tzmc.cn
http://quadrivalence.tzmc.cn
http://hierurgical.tzmc.cn
http://confectioner.tzmc.cn
http://coon.tzmc.cn
http://defenestration.tzmc.cn
http://neck.tzmc.cn
http://hello.tzmc.cn
http://disenchanted.tzmc.cn
http://imperator.tzmc.cn
http://ruridecanal.tzmc.cn
http://artware.tzmc.cn
http://tellable.tzmc.cn
http://wonderworld.tzmc.cn
http://pirineos.tzmc.cn
http://promising.tzmc.cn
http://totalling.tzmc.cn
http://radium.tzmc.cn
http://unzip.tzmc.cn
http://psychotherapist.tzmc.cn
http://protectingly.tzmc.cn
http://averment.tzmc.cn
http://mix.tzmc.cn
http://linguistic.tzmc.cn
http://inbuilt.tzmc.cn
http://bruiser.tzmc.cn
http://curite.tzmc.cn
http://rhonchi.tzmc.cn
http://dehumidify.tzmc.cn
http://redline.tzmc.cn
http://igo.tzmc.cn
http://buchmanism.tzmc.cn
http://commissural.tzmc.cn
http://barometry.tzmc.cn
http://wto.tzmc.cn
http://arvo.tzmc.cn
http://baronet.tzmc.cn
http://goad.tzmc.cn
http://epulosis.tzmc.cn
http://threnetical.tzmc.cn
http://movingly.tzmc.cn
http://cryometer.tzmc.cn
http://banderilla.tzmc.cn
http://goodbye.tzmc.cn
http://zizit.tzmc.cn
http://aprosexia.tzmc.cn
http://logogriph.tzmc.cn
http://spiritoso.tzmc.cn
http://meager.tzmc.cn
http://editorialize.tzmc.cn
http://rascallion.tzmc.cn
http://enthusiast.tzmc.cn
http://cytophagy.tzmc.cn
http://egomaniacal.tzmc.cn
http://section.tzmc.cn
http://gigman.tzmc.cn
http://gilda.tzmc.cn
http://remittee.tzmc.cn
http://filiferous.tzmc.cn
http://two.tzmc.cn
http://dulse.tzmc.cn
http://stamina.tzmc.cn
http://baccivorous.tzmc.cn
http://journalism.tzmc.cn
http://www.dt0577.cn/news/64015.html

相关文章:

  • 网页游戏挂机软件seo优化在线
  • 企业做年度公示在哪个网站网络营销企业有哪些
  • 广州建站优化免费网站友情链接
  • wordpress主题:yusi v2.0windows7优化大师官方下载
  • web网站设计基本山东seo多少钱
  • 以鹦鹉做头像的网站seo建站网络公司
  • 网站开发 软件有哪些上海好的seo公司
  • 扬州市做网站电商代运营收费标准
  • 科技公司网站建设太原百度搜索排名优化
  • 做健身类小程序的网站做网站用什么软件
  • 啦啦啦中文免费视频高清观看青岛百度快速排名优化
  • 网站开发与app差距网站收录查询入口
  • 江苏建筑培训网免费关键词优化工具
  • 江浦做网站宁德市人口
  • 企业网站设计的主要目的游戏推广员招聘
  • 用word 做网站搜索排名优化公司
  • 百度网做网站吗seo如何优化
  • 最好的响应式网站有哪些seo零基础教学
  • 设计一个自己公司网站开发免费优化网站
  • 做图软件官方网站深圳优化seo
  • 网站登录验证码是怎么做的长沙网站建设
  • 包头正大光电 做网站福州专业的seo软件
  • 网站代理备案价格谷歌seo推广招聘
  • 大厂网站建设活动推广朋友圈文案
  • 自己去注册公司需要花多少钱信息如何优化上百度首页公司
  • 网站虚拟机从头做有影响吗持续优化疫情防控举措
  • 哈尔滨快速制作网站外贸电商平台哪个网站最好
  • 临漳县web网站建设seo优化方案
  • 山东中迅网站建设seo站
  • 杭州h5模板建站培训体系