Scatter
汇总
Scatter 类可创建散点图。 散点图能够可视化两个数值变量之间的关系,即在 x 轴与 y 轴上分别显示这两个变量。 对于每条记录而言,每当两个变量在图表中相交便绘制一个点。 生成的点将构成一个有序结构,两个变量之间的关系随即形成。
讨论
创建此对象时,必须使用参数名指定类构造函数的可选参数;这些可选参数不能通过参数位置指定。 有关如何使用关键字指定参数的示例,请参阅代码示例部分。
语法
Scatter(x, y, {splitCategory}, {sizeField}, {sizeMin}, {sizeMax}, {multiSeriesDisplay}, {miniChartsPerRow}, {showPreviewChart}, {showTrendLine}, {title}, {description}, {xTitle}, {yTitle}, {dataSource}, {displaySize}, {theme})
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
x |
The field name for the x-axis variable. The field must be a numeric type, or a string type with band names (for raster layers). |
String |
|
y |
The field name for the y-axis variable. The field must be a numeric type, or a string type with band names (for raster layers). |
String |
|
splitCategory (可选) |
A categorical field that adds a separate series for each unique value in the field. |
String |
|
sizeField (可选) |
The field used to determine the size of the proportional symbol when creating a bubble plot. |
String |
|
sizeMin (可选) |
The minimum size for points in a bubble plot. |
Integer |
|
sizeMax (可选) |
The maximum size for points in a bubble plot. |
Integer |
|
multiSeriesDisplay (可选) |
The display type for a scatter plot with multiple series.
|
String |
|
miniChartsPerRow (可选) |
每行显示的迷你图表的数量。 |
Integer |
|
showPreviewChart (可选) |
指定是否在格网图表中显示预览图表。
(默认值为 False) |
Boolean |
|
showTrendLine (可选) |
Indicates whether the trend line is visible in the scatter plot.
|
Boolean |
|
title (可选) |
图表的标题。 标题文本显示在图表视图的顶部,并在 内容 窗格中用作图表的标注。 |
String |
|
description (可选) |
图表的描述。 该描述文本会显示于图表视图底部。 |
String |
|
xTitle (可选) |
图表 x 轴的标题。 |
String |
|
yTitle (可选) |
图表 y 轴的标题。 |
String |
|
dataSource (可选) |
图表的数据源。 当通过 |
Object |
|
displaySize (可选) |
当使用 |
List |
|
theme (可选) |
指定将应用于图表的主题。
|
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
color (读取和写入) |
将应用于每个图表系列的颜色。 该值应为十六进制字符串值的列表。 如果未设置此属性,则系列颜色将匹配符号系统颜色(如果适用)。否则,将应用标准调色板。 |
List |
|
dataSource (读取和写入) |
图表的数据源。 当通过 |
Object |
|
description (读取和写入) |
图表的描述。 该描述文本会显示于图表视图底部。 |
String |
|
displaySize (读取和写入) |
当使用 |
List |
|
enableServerSideProcessing (读取和写入) |
指定当数据来自企业级数据库或云数据仓库时,是否将使用 服务器端处理 。
|
Boolean |
|
legend (读取和写入) |
图表图例的属性。
|
Object |
|
miniChartsPerRow (读取和写入) |
每行显示的迷你图表的数量。 |
Integer |
|
multiSeriesDisplay (读取和写入) |
指定具有多个系列的散点图的显示类型。
|
String |
|
showPreviewChart (读取和写入) |
指定是否在格网图表中显示预览图表。
|
Boolean |
|
showTrendLine (读取和写入) |
指定是否将在散点图中显示 趋势线 。
|
Boolean |
|
sizeField (读取和写入) |
当创建气泡图时,将用于确定比例符号大小的字段。 |
String |
|
sizeMax (读取和写入) |
气泡图中点的最大 尺寸 。 |
Integer |
|
sizeMin (读取和写入) |
气泡图中点的最小 尺寸 。 |
Integer |
|
splitCategory (读取和写入) |
类别字段,将为字段中每一个唯一值添加单独的 系列 。 |
String |
|
theme (读取和写入) |
指定将应用于图表的主题。
|
String |
|
title (读取和写入) |
图表的标题。 标题文本显示于图表视图顶部,并用作 内容 窗格中 按绘制顺序列出 选项卡 |
String |
|
type (只读) |
用于指示图表类型的字符串值。 |
String |
|
x (读取和写入) |
x 轴变量的字段名称。 该字段必须为数值字段。 |
String |
|
xAxis (读取和写入) |
指定 x 轴的属性。
|
Object |
|
y (读取和写入) |
y 轴变量的字段名称。 该字段必须为数值字段。 |
String |
|
yAxis (读取和写入) |
指定 y 轴的属性。
|
Object |
方法
addToLayer(layer_or_layerfile)
addToLayer 方法可将图表对象添加到图层或表视图。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
layer_or_layerfile |
The chart will be added to the target object. This argument can be a |
Object |
将图表添加到现有图层。
import arcpy
# Insert creation of chart object here
# ...
aprx = arcpy.mp.ArcGISProject("current")
map = aprx.listMaps()[0]
censusLayer = map.listLayers('Census Block Groups')[0]
# Add chart object to a layer
chart.addToLayer(censusLayer)
exportToJPEG(path, width, height)
exportToJPEG 方法用于将图表导出为 JPEG 格式。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
path |
The path where the chart will be exported in JPEG format. |
String |
|
width |
The width of the output graphic. |
Integer |
|
height |
The height of the output graphic. |
Integer |
将具有要素服务数据源的图表导出到 .jpeg 文件中。
import arcpy
# Insert creation of chart object here
# ...
featureServiceURL = r'https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/CrimesChiTheft/FeatureServer/0'
# Set data source of chart object to a feature service URL
chart.dataSource = featureServiceURL
# Save the chart to file with dimensions width=800, height=600
chart.exportToJPEG('theftsPerBeat.jpg', 800, 600)
exportToPNG(path, width, height)
exportToPNG 方法用于将图表导出为 PNG 格式。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
path |
The path where the chart will be exported in PNG format. |
String |
|
width |
The width of the output graphic. |
Integer |
|
height |
The height of the output graphic. |
Integer |
从图层访问现有图表,更新标题,然后将其导出为 .png 文件。
import arcpy
lyr = arcpy.mp.ArcGISProject('current').listLayers()[0]
# Retrieve the first chart belonging to the layer
chart = lyr.listCharts()[0]
# Update chart title
chart.title = 'Voter Turnout by State'
# Save the chart to PNG file with dimensions width=800, height=600
chart.exportToPNG('populationByState.png', 800, 600)
exportToSVG(path, width, height)
exportToSVG 方法可将图表导出为 SVG 格式。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
path |
将图表以 SVG 格式导出时的路径。 |
String |
|
width |
输出图形的宽度。 |
Integer |
|
height |
输出图形的高度。 |
Integer |
将具有工程图层数据源的图表导出到 .svg 文件中。
import arcpy
# Insert creation of chart object here
# ...
aprx = arcpy.mp.ArcGISProject('current')
censusLayer = aprx.listMaps()[0].listLayers('Census Block Groups')[0]
# Set data source of chart object to a layer in current project
chart.dataSource = censusLayer
# Save the chart to file with dimensions width=500, height=500
chart.exportToSVG('populationByState.svg', 500, 500)
updateChart()
该 updateChart 方法可更新图表属性,以同步对象与之前添加到图层的图表之间的更改。
可以使用 updateChart 方法将图表属性更改同步到图层中。
import arcpy
# Insert creation of chart object here
# ...
chart.addToLayer(myLayer)
# Further modification is necessary
chart.description = "Data from the U.S. Census Bureau"
chart.updateChart()
代码示例
创建散点图并将其添加到当前工程中的图层。
import arcpy
aprx = arcpy.mp.ArcGISProject("current")
map = aprx.listMaps()[0]
censusLayer = map.listLayers("Census Block Groups")[0]
chart = arcpy.charts.Scatter(x="Per_Vacant", y="Pop_Density", xTitle="Vacant Housing %",
yTitle="Population Density (per Sq. Mile)")
chart.addToLayer(censusLayer)