In a python script I'm trying to save a graph to a .png file with graph output from arcpy.StackProfile_3d but the .png file shows an empty graph. The table created from arcpy.StackProfile_3d shows values. Does anybody know why the graph is still empty?

import arcpy
# Set Local Variables
profileLine = "C:/temp/data.gdb/profile"
profileTargets = "C:/temp/data.gdb/raster"
profileTable = "C:/temp/value.dbf"
graphName = "Sample Graph"
outGraph = "C:/temp/graph.png"

# Execute StackProfile
arcpy.StackProfile_3d(profileLine, profileTargets, profileTable, graphName)

# # Execute SaveGraph
arcpy.SaveGraph_management(graphName, outGraph, "MAINTAIN_ASPECT_RATIO")

enter image description here

  • I am struggling to run the two commands together, I'm trying to use with loop to generate various figures automatically, can anyone help me? Thank you!
    – user52502
    May 21, 2015 at 19:56

3 Answers 3


It seems there is a bug with this function in version 10.1: Bug NIM-092377 - When using Python to generate a Stack Profile, 3D Analyst (arcpy.StackProfile_3d), the output table and graph generated are blank. It doesn't correspond fully to your description as your table is not empty, though. Apparently it's solved with 10.2, you could try with this version if you have the possibility to upgrade.

  • Thanks, in certain cases the value table is also empty but not with the code I used above. So I guess it's more like two separated bugs. Mar 31, 2014 at 9:33

I created a workaround solution to the problem.

Instead of using the graph output from StackProfile_3d it is possible to create a graph from the value table.

With this approach it is also possible to customize the look of the graph using a graph text template which first must be created, see intructions in the code below.

import arcpy
# Set Local Variables
homedir = "C:/mpo/opgaver/grafer/data.gdb/"
home = "C:/mpo/opgaver/grafer/"
profileLine = homedir+"profile"
profileTargets = homedir+"raster"
profileTable = homedir+"value"
out_graph_name = "VerticalBarGraph6"
out_graph_pic = home+"graph.png"
# Graph template to use, 
# 1) Create graph in ArcGIS: View-> Graphs-> Create Graph-> Next-> Finish
# 2) Then save as template file: Rigth click graph from 1)-> Export-> Native-> Text-> Save
# 3) Rename .txt file to .tee
input_template = home+"line2.tee"

# Execute StackProfile
arcpy.StackProfile_3d(profileLine, profileTargets, profileTable)

# Create the graph
graph = arcpy.Graph()

# Add a vertical line series to the graph
graph.addSeriesLineVertical  (profileTable, "FIRST_Z", "FIRST_DIST", "" , "")

# Output a graph, which is created in-memory
arcpy.MakeGraph_management(input_template, graph, out_graph_name)

# Save the graph as an image
arcpy.SaveGraph_management(out_graph_name, out_graph_pic,"IGNORE_ASPECT_RATIO", 900, 200)
  • thanks so much your code helped me a lot, but I have a problem if I run the code twice there is an error it say me that the graph already exists even if I use: if arcpy.Exists(prof): arcpy.Delete_management(prof) Do you know what can I do? Thanks!
    – user29404
    Apr 21, 2014 at 19:26
  • You're welcome :-). I always have the checkbox checked for "Geoprocessing -> Geoprocessing Options -> Overwrite the outputs of geoprocessing operations" in this case you won't see the error. But otherwise it should be possible to use the arcpy.Delete_management as you mentioned. I have updated my code to include this. If you do it the same way in your scripts it should work without the overwrite option. Apr 22, 2014 at 12:20

** I used this simple script and it worked for me>>>** the most important thing is to create {{{{{Graph.grf or .tee}}}} from the same files(and fields) on which you want to run the script.

import arcpy
    # Graph Variables
    out_graph_name = "VerticalBarGraph"
    out_graph_bmp = "VerticalBarGraph13.bmp"
    input_template = "service coverage Graph.grf"
    input_data_served = 'served.shp'
    input_data_unserved = 'unserved.shp'
    # Create the graph
    graph = arcpy.Graph()
    # Add a vertical bar series to the graph
    graph.addSeriesBarVertical(input_data_served, "area")
    graph.addSeriesBarVertical(input_data_unserved, "area2")
    # Specify the title of the Graph
    graph.graphPropsGeneral.title = "service1 coverage"
    # Output a graph, which is created in-memory
    arcpy.MakeGraph_management(input_template, graph, out_graph_name)
    # Save the graph as an image
    arcpy.SaveGraph_management(out_graph_name, out_graph_bmp, "MAINTAIN_ASPECT_RATIO", 600, 375)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.