Skip to main content

Guide

汇总

Guide 类包含用于配置图表参考线的属性。

讨论

创建此对象时,必须使用参数名指定类构造函数的可选参数;这些可选参数不能通过参数位置指定。 有关如何使用关键字指定参数的示例,请参阅代码示例部分。

语法

Guide(guideType, {name}, {label}, {valueFrom}, {valueTo}, {valueFromField}, {valueFromFieldAggregationType}, {polyline}, {lineColor}, {lineWidth}, {lineDashStyle}, {fillColor})

名称 说明 数据类型

guideType

Specifies the type of guide that will be created.

  • line—A line guide will be created. Use this value in conjunction with the valueFrom argument.

  • range—A range guide will be created. Use this value in conjunction with the valueFrom and valueTo arguments.

  • polyline—A polyline or point guide will be created. Use this value in conjunction with the polyline argument.

String

name

(可选)

The unique name for the guide that will appear in the Chart Properties pane.

String

label

(可选)

The guide label that will be displayed in the chart.

String

valueFrom

(可选)

The location of the guide when creating a line guide, or the start location of the range when creating a range guide. Use a double value for numeric axes and a datetime object for temporal axes.

Object

valueTo

(可选)

The end location of the range when creating a range guide. Use a double value for numeric axes and a datetime object for temporal axes.

Object

valueFromField

(可选)

The field name whose values will be used to calculate the location of a data-driven guide. Use this argument in conjunction with the valueFromFieldAggregationType argument.

String

valueFromFieldAggregationType

(可选)

Specifies the statistical calculation that will be used to determine the location of a data-driven guide. Use this argument in conjunction with the valueFromField argument.

  • MEAN—The mean of all values will be calculated and applied.

  • MEDIAN—The median of all values will be identified and applied.

  • MIN—The minimum value will be identified and applied.

  • MAX—The maximum value will be identified and applied.

String

polyline

(可选)

A list of coordinates that will be used when creating a polyline guide. Coordinates should be in row-major order. Specifying a single coordinate pair will create a point guide.

Create a polyline guide.

# Coordinates will be: (0, 2), (10, 12), (20, 15)
coordinates = [0, 2, 10, 12, 20, 15]
guide = arcpy.charts.Guide(guideType="polyline", polyline=coordinates)

List

lineColor

(可选)

The color of a line guide in hexadecimal format.

String

lineWidth

(可选)

The width of a line guide.

Double

lineDashStyle

(可选)

Specifies the dash style that will be used for a line guide.

  • solid—A solid style will be used.

  • dot—A dot style will be used.

  • dash—A dash style will be used.

  • dashDot—A dash-dot style will be used.

  • longDash—A long-dash style will be used.

  • longDashDot—A long-dash-dot style will be used.

String

fillColor

(可选)

The fill color of a range guide in hexadecimal format.

String

属性

名称 说明 数据类型

fillColor

(读取和写入)

十六进制格式的范围参考线的填充颜色。

String

guideType

(读取和写入)

指定要创建的参考线类型。

  • line—将创建线参考线。 将此值与 valueFrom 属性配合使用。

  • range—将创建范围参考线。 将此值与 valueFromvalueTo 属性配合使用。

  • polyline—将创建折线或点参考线。 将此值与 polyline 属性配合使用。

String

label

(读取和写入)

将显示在图表中的参考线标注。

String

lineColor

(读取和写入)

十六进制格式的线参考线的颜色。

String

lineDashStyle

(读取和写入)

指定用于线参考线的划线样式。

  • solid—将使用实线样式。

  • dot—将使用点样式。

  • dash—将使用虚线样式。

  • dashDot—将使用点划线样式。

  • longDash—将使用长划线样式。

  • longDashDot—将使用长点划线样式。

String

lineWidth

(读取和写入)

线参考线的宽度。

Double

name

(读取和写入)

将显示在 图表属性 窗格中的参考线的唯一名称。

String

polyline

(读取和写入)

创建折线参考线时将使用的坐标列表。 坐标应按行优先顺序排列。 指定单一坐标对时,将创建一个点参考线。

创建折线参考线。

# Coordinates will be: (0, 2), (10, 12), (20, 15)
coordinates = [0, 2, 10, 12, 20, 15]
guide = arcpy.charts.Guide(guideType="polyline", polyline=coordinates)

List

valueFrom

(读取和写入)

创建线参考线时,参考线的位置,或创建范围参考线时范围的起始位置。 对数字轴,使用双精度值;对时间轴,使用 datetime 对象。

Object

valueFromField

(读取和写入)

其值将用于计算数据驱动参考线位置的字段名称。 将此属性与 valueFromFieldAggregationType 属性配合使用。

String

valueFromFieldAggregationType

(读取和写入)

指定将用于确定数据驱动参考线位置的统计计算。 将此属性与 valueFromField 属性配合使用。

  • MEAN—将计算并应用所有值的平均值。

  • MEDIAN—将识别并应用所有值的中值。

  • MIN—将识别并应用最小值。

  • MAX—将识别并应用最大值。

String

valueTo

(读取和写入)

创建范围参考线时范围的结束位置。 对数字轴,使用双精度值;对时间轴,使用 datetime 对象。

Object

代码示例

参考线示例 1

向散点图添加两条显示每个轴平均值的参考线。

import arcpy

chart = arcpy.charts.Scatter(x="voter_turnout", y="per_capita_income", dataSource="VoterTurnout2020")

# Create and configure guides
guideX = arcpy.charts.Guide(guideType="line", valueFrom=65.6, label="Avg. Voter Turnout")
guideY = arcpy.charts.Guide(guideType="line", valueFrom=26823.8, label="Avg. Per Capita Income")

# Add guides to appropriate axis
chart.xAxis.addGuide(guideX)
chart.yAxis.addGuide(guideY)

chart.exportToSVG("chart_with_guides.svg")
参考线示例 2

将数据驱动的参考线添加到条形图,以显示 y 轴的平均值。

import arcpy

lyr = arcpy.mp.ArcGISProject("current").listMaps()[0].listLayers()[0]
chart = arcpy.charts.Bar(x="State", y="TotalPop", aggregation="MEAN")

# Create data-driven guide
guide = arcpy.charts.Guide("line", valueFromField="TotalPop", valueFromFieldAggregationType="MEAN")

# Add guide to y-axis
chart.yAxis.addGuide(guide)

chart.addToLayer(lyr)