0

Matplotlib を使用して複数のシリーズをループでプロットするのに問題があります (Matplotlib 1.0.0、Python 2.6.5、ArcGIS 10.0)。フォーラムの調査により、同じプロットに複数のシリーズをプロットするために、Axes オブジェクトを適用することがわかりました。これがループ外で生成されたデータ (サンプル スクリプト) に対してどのように機能するかはわかりますが、同じ構文を挿入し、データベースからデータをプルするループに 2 番目のシリーズを追加すると、次のエラーが発生します。

": サポートされていないオペランド タイプ -: 'NoneType' および 'NoneType' の実行に失敗しました (ChartAge8)。"

以下は私のコードです - 提案やコメントは大歓迎です!

import arcpy
import os
import matplotlib
import matplotlib.pyplot as plt

#Variables
FC = arcpy.GetParameterAsText(0) #feature class
P1_fld = arcpy.GetParameterAsText(1) #score field to chart
P2_fld = arcpy.GetParameterAsText(2) #score field to chart
plt.subplots_adjust(hspace=0.4)
nsubp = int(arcpy.GetCount_management(FC).getOutput(0)) #pulls n subplots from FC
last_val = object()

#Sub-plot loop
cur = arcpy.SearchCursor(FC, "", "", P1_fld)
i = 0
x1 = 1 # category 1 locator along x-axis
x2 = 2 # category 2 locator along x-axis
fig = plt.figure()
for row in cur:
    y1 = row.getValue(P1_fld)
    y2 = row.getValue(P2_fld)
    i += 1
    ax1 = fig.add_subplot(nsubp, 1, i)
    ax1.scatter(x1, y1, s=10, c='b', marker="s")
    ax1.scatter(x2, y2, s=10, c='r', marker="o")
del row, cur

#Save plot to pdf, open
figPDf = r"path.pdf"
plt.savefig(figPDf)
os.startfile("path.pdf")
4

1 に答える 1

0

同じプロットを再利用していくつかのものをプロットしたい場合は、ループの外に図オブジェクトを作成し、毎回同じオブジェクトにプロットします。次のようになります。

fig = plt.figure()

for row in cur:
    y1 = row.getValue(P1_fld)
    y2 = row.getValue(P2_fld)
    i += 1

    ax1 = fig.add_subplot(nsubp, 1, i)
    ax1.scatter(x1, y1, s=10, c='b', marker="s")
    ax1.scatter(x2, y2, s=10, c='r', marker="o")
del row, cur
于 2013-07-01T21:47:35.373 に答える