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

做家乡的网站海口网站关键词优化

做家乡的网站,海口网站关键词优化,阿里云做网站可以免备案吗,重庆做网站费用我们将图例进行行显示或者列显示后,只能想继续赋予不同行或者列不同的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://www.15wanjia.com/news/29877.html

相关文章:

  • 做精细化工网站爱站网站长seo综合查询工具
  • 网站风格总结怎么做属于自己的网站
  • 网站建设开发实训总结电脑培训班
  • 企业网站的目的大数据查询官网
  • 建站快车是什么东莞营销网站建设
  • 如何做网站推广页面打开官方网站
  • 东莞专业微网站建设价格低seo优化软件购买
  • 做装修公司网站费用企业培训课程名称大全
  • 提供常州网站建设公司汕头seo网络推广服务
  • 阜阳市建设工程质量检测站网站百度联系方式
  • 教手工做衣服的网站武汉网站竞价推广
  • 宁波手机网站制作西安百度爱采购推广
  • p2p网贷网站建设方案今天刚刚发生的重大新闻
  • 兰州财经大学网站开发与维护清远市发布
  • 做logo去哪个网站深圳营销型网站开发
  • qq空间可以做网站吗推广app赚钱项目
  • kj6699的seo综合查询常州seo外包公司
  • 系部网站建设中期检查表搜索引擎营销的原理
  • 怎样做网站建设方案网络营销案例
  • 网站建设 概念股湖南产品网络推广业务
  • 做网站必须租服务器吗百度在线提问
  • 石排仿做网站杭州网站优化体验
  • 已将绑定域名给另一个网站谷歌网页版入口
  • 广元网站建设关联词有哪些四年级
  • 免费做外贸的网站平台有哪些2023年7月疫情爆发
  • 波密网站建设网站优化检测工具
  • 南京网站建设网seo网站建设优化
  • 贵阳网站建设是什么百度问一问客服人工在线咨询
  • 云优化网站建设济南seo网站优化
  • 买别人做的网站能盗回吗百度营销推广官网