![]() ![]() ![]() Now the answer to the second question (how to use the primitive replace-item to change an item in a list that is inside another list – that’s in a “list of list”):.So, it is only “re-setting” the list replacing the desired item by the desired value.Check the picture below for an example using the command center: Let’s say that you have a list called myList and you want to replace the first item by the string “a”.Answer to the first question (how to use the primitive replace-item to change a list):.But how is it done? And how does it work with list of lists? #Set negative values to 0 (artifact from small sample sizes) s2max = s2.max().max() s2min = s2.min().min() names = problem n = len(names) ticklocs = np.linspace(0, 2*pi, n+1) locs = ticklocs filtered_names, filtered_locs = filter(sobol_indices, names, locs, criterion, threshold) # setup figure # fig = plt.figure() ax = fig.add_subplot(111, polar=True) ax.grid(False) ax.t_visible(False) ax.set_xticks(locs) # Fixed # ax.set_xticklabels(names, fontsize=12) ax.set_yticklabels() ax.set_ylim(top=1.4) legend(ax) # plot ST plot_circles(ax, filtered_locs, filtered_names, max_s_radius, sobol_stats, smax, smin, 'w', 'k', 1, 9) # plot S1 plot_circles(ax, filtered_locs, filtered_names, max_s_radius, sobol_stats, smax, smin, 'k', 'k', 1, 10) # plot S2 for name1, name2 in binations(zip(filtered_names, filtered_locs), 2): name1, loc1 = name1 name2, loc2 = name2 weight = s2.loc lw = 0.5+max_linewidth_s2*normalize(weight, s2min, s2max) ax.plot(,, c='darkgray', lw=lw, zorder=1) return fig from matplotlib.legend_handler import HandlerPatch class HandlerCircle(HandlerPatch): def create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans): center = 0.5 * width - 0.5 * xdescent, 0.5 * height - 0.5 * ydescent p = plt.Circle(xy=center, radius=orig_handle.radius) self.update_prop(p, orig_handle, legend) p.set_transform(trans) return def legend(ax): some_identifiers =, , lw=8, color='darkgray')] ax.legend(some_identifiers,, loc=(1,0.75), borderaxespad=0.According to the text in the NetLogo dictionary “”replace-item” is used in conjunction with “set” to change a list”. # Error countdown_df = netlogo.patch_report('countdown') # Alternative way countdown_df=netlogo.report('map of s] sort patches') # Reshape for 51 by 51 square countdown_df=countdown_df.reshape(51,51) # Convert to DataFrame countdown_df = pd.DataFrame(countdown_df) # Change index and column names countdown_df.columns= countdown_df.index= # Make a plot fig, ax = plt.subplots(1) patches = sns.heatmap(countdown_df, xticklabels=5, yticklabels=5, cbar_kws= sobol_stats = pd.DataFrame(sobol_stats, index=problem) smax = sobol_stats.max().max() smin = sobol_stats.min().min() # dataframe with s2 s2 = pd.DataFrame(sobol_indices, index=problem, columns=problem) s2=0. To get data from patches, we need to use. ![]() ex_data] # Import the data to col1, col2 and col3 attributes of the 'breed' netlogo.write_NetLogo_attriblist(ex_data], 'breed'). write_NetLogo_attriblist # ex_data is a pandas DataFrame having three columns : col1, col2, and col3. repeat_report # Run 100ticks mand('repeat 100 ') # or # Run 100 ticks and Report 'count wolves' netlogo.repeat_report(, 100, go='go') Import data to the Netlogo model. report # open Netlogo netlogo = pyNetLogo.NetLogoLink(gui=True) # Load the Model netlogo.load_model('C:/Program Files/NetLogo 6.1.1/./Wolf Sheep ogo') # Setup and Choose model-version = "sheep-wolves-grass" mand('setup') # Get the coordinates of agents(sheep) from Netlogo x = netlogo.report('map of s] sort sheep') y = netlogo.report('map of s] sort sheep') # Make a plot fig, ax = plt.subplots(1) ax.scatter(x, y, s=4) ax.set_xlabel('xcor') ax.set_ylabel('ycor') ax.set_aspect('equal') fig.set_size_inches(5,5) plt.show() ![]() conda create -n netlogo-env python=3.8 # For JPype conda install -c conda-forge jpype1 # For PyNetLogo pip install pynetlogo Import Libraries import pandas as pd import numpy as np from scipy import stats import matplotlib.pyplot as plt import seaborn as sns import pyNetLogo sns.set_style('white') sns.set_context('talk') %matplotlib inline Get Data from Netlogo simulation. JPype package is more stable in Pyhton 3.8 or older. I strongly recommend creating a virtual environment for a new package. Paper : PyNetLogo: Linking NetLogo with Python PyNetlogo Homepage PyNetlogo GithubĪnd One more: My tutorial for PyNetlogo Install and Virtual Environment There are three important webpages as follows: I do not think it is well managed after the release of version 0.3. PyNetlogo is a python package to link Netlog to Python. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |