Background: I have some python code that I need help with parameter passing into the MakeGraph_management arcpy function. I would like to create a two-series vertical line graph for every pair of input point feature classes using the 'zip' function (ie. input fgdb1/fc1 and fgdb2/fc1 >> MakeGraph >> graph1.png; input fgdb1/fc2 and fgdb2/fc2 >> MakeGraph >> graph2.png, ...).
My Problem: Now I am trying to create graphs in batch using ArcPy/python 2.7.3, but have been struggling with the way these ArcPy functions work around the template file. I created a graph template in ArcGIS 10.2 with everything setup (axis labels, titles, footers, legend names, etc.) I just need to get the data input working to correspond with Series1 and Series2.
The code below successfully iterates and creates graphs for every pair of input datasets as planned. However, the graphs contain no plotted data. I thought I could just use MakeGraph_management and SaveGraph_management since I have a template instead of also working with the ArcGIS Graph class.
# Import system modules import arcpy from arcpy import env # enable overwrite outputs arcpy.env.overwriteOutput = True # input feature directory: yr0_transects dir_yr0_transects = r"W:\Working\abcdefg_working\PointDistance\data\point_distance\year0\output\output_year0.gdb" # input feature directory: yr1_transects dir_yr1_transects = r"W:\Working\abcdefg_working\PointDistance\data\point_distance\year1\output\output_year1.gdb" # output directory outWorkspace = r"W:\Working\abcdefg_working\Profiles" # Create list of year 0 Transect features arcpy.env.workspace = dir_yr0_transects yr0_transects_list = sorted(arcpy.ListFeatureClasses()) # Create list of year 1 Transect features arcpy.env.workspace = dir_yr1_transects yr1_transects_list = sorted(arcpy.ListFeatureClasses()) # Set workspace arcpy.env.workspace = r"W:\Working\abcdefg_working\Profiles" # Set local variables graph_tee = r"W:\Working\abcdefg_working\Profiles\Profile_graph_template.tee" for yr0_transect, yr1_transect in zip(yr0_transects_list, yr1_transects_list): try: #Cast to string because ListFC() returns unicode. string_yr0_transect = str(yr0_transect) string_yr1_transect = str(yr1_transect) # create title for graph graph_title = "Profiles, B.F.E." + string_yr0_transect[0:17] + string_yr0_transect[47:] # Create the graph object graph = arcpy.Graph() # Add a vertical bar series to the graph graph.addSeriesLineVertical(yr0_transect) graph.addSeriesLineVertical(yr1_transect) # Specify the title of the Graph graph.graphPropsGeneral.title = graph_title # Create graph output name output_graph_name = string_yr0_transect[0:17] + string_yr0_transect[47:] + "_profile" + ".png" # Output a vertical line graph, which is created in-memory arcpy.MakeGraph_management(graph_tee, graph, "temp_graph") #Execute SaveGraph mygraph = arcpy.SaveGraph_management("temp_graph", output_graph_name, "MAINTAIN_ASPECT_RATIO", "1024", "768") del mygraph except: print arcpy.GetMessages()