I’ve a perform that plots histogram subplots from an array of numbers.
I wish to change the “bins” based mostly on the argument I handed to the perform. If I cross “X_arr” I would like the step dimension of arange to be 1; and 10 if I cross Y_arr. And naturally related conduct for the filenames. I’ve greater than 100 arrays that follows a sample, so passing a kwarg will not be possible.
If I do one thing like the next, it throws
FutureWarning: elementwise comparability failed; returning scalar as a substitute, however sooner or later will carry out elementwise comparability error. I do know that the argument “array” is interpreted because the numpy array it was handed to; I do not know methods to make the code to take it because the phrase “array”.
def plot(array): if array == 'X_arr': bins = np.arange(0,int(np.amax(array)+1),1) filename = 'hist_X.png' elif array == 'Y_arr': bins = np.arange(0,int(np.amax(array)+1),10) filename = 'hist_Y.png' -some plotting here- plt.setp(axs, xticks=bins) plt.savefig(filename) plt.present()