ScatterMatrix
汇总
ScatterMatrix 类可创建散点图矩阵。 散点图矩阵是 散点图 的格网(或矩阵),用于可视化变量组合之间的二元关系。 矩阵中的每个散点图可视化一对变量之间的关系,之后便可在一个图表中探索许多关系。
讨论
创建此对象时,必须使用参数名指定类构造函数的可选参数;这些可选参数不能通过参数位置指定。 有关如何使用关键字指定参数的示例,请参阅代码示例部分。
语法
ScatterMatrix(fields, {showTrendLine}, {lowerLeft}, {upperRight}, {diagonal}, {sort}, {sortBy}, {title}, {description}, {dataSource}, {displaySize}, {theme})
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
fields |
要在矩阵中显示的字段名称列表。 至少需要 3 个字段。 |
List |
|
showTrendLine (可选) |
指示是否在散点图中显示趋势线。
|
Boolean |
|
lowerLeft (可选) |
设置矩阵左下半部分的显示。
|
String |
|
upperRight (可选) |
设置矩阵右上半部分的显示。
|
String |
|
diagonal (可选) |
设置对角线视图的显示。
|
String |
|
sort (可选) |
应用于矩阵的排序方法。
|
String |
|
sortBy (可选) |
当您希望根据目标字段的指标得分对行进行排序时,用于对矩阵进行排序的方法。
|
String |
|
title (可选) |
图表的标题。 标题文本显示在图表视图的顶部,并在 内容 窗格中用作图表的标注。 |
String |
|
description (可选) |
图表的描述。 该描述文本会显示于图表视图底部。 |
String |
|
dataSource (可选) |
图表的数据源。 当通过 |
Object |
|
displaySize (可选) |
当使用 |
List |
|
theme (可选) |
指定将应用于图表的主题。
|
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
dataSource (读取和写入) |
图表的数据源。 当通过 |
Object |
|
description (读取和写入) |
图表的描述。 该描述文本会显示于图表视图底部。 |
String |
|
diagonal (读取和写入) |
设置对角线视图的显示。
|
String |
|
displaySize (读取和写入) |
当使用 |
List |
|
fields (读取和写入) |
要在矩阵中显示的字段名称列表。 至少需要 3 个字段。 |
List |
|
lowerLeft (读取和写入) |
设置矩阵左下半部分的显示。
|
String |
|
showTrendLine (读取和写入) |
指示是否在散点图中显示趋势线。
|
Boolean |
|
sort (读取和写入) |
应用于矩阵的排序方法。
|
String |
|
sortBy (读取和写入) |
当您希望根据目标字段的指标得分对行进行排序时,用于对矩阵进行排序的方法。
|
String |
|
theme (读取和写入) |
指定将应用于图表的主题。
|
String |
|
title (读取和写入) |
图表的标题。 标题文本显示于图表视图顶部,并用作 内容 窗格中 按绘制顺序列出 选项卡 |
String |
|
type (只读) |
用于指示图表类型的字符串值。 |
String |
|
upperRight (读取和写入) |
设置矩阵右上半部分的显示。
|
String |
方法
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()
代码示例
可以使用图层名称来创建散点图矩阵,然后将其导出至 .svg 文件。
import arcpy
chart = arcpy.charts.ScatterMatrix(fields=["copd", "diabetes", "heart_failure", "hypertension", "high_cholesterol"],
lowerLeft="R_SQUARED", upperRight="PREVIEW_PLOT",
dataSource="health_indicators", displaySize=(800, 500))
chart.exportToSVG("scatter_matrix.svg")