I have a plotting function to plot some data. I would like to syntax it in a way that it will automatically get y limits,EXCEPT when I manually want to pass specific limits to it.
I have done that by manually changing the value in a variable,when i want my own axis limits to be used. However I understand that this is just a work around, so any suggestions are welcome:
def plot_data(dataset, set_own_lim=1, my_ymin, my_ymax):
ax=plt.subplot(111)
if set_own_lim=0:
ax.set_ylim(min(dataset),max(dataset)) #calculating y range from data
else:
ax.set_ylim(my_ymin, my_ymax) # uses my own limits for y range
ax.plot(dataset)
I would like to define a function in a way, that I could call it like plot_data(some_data) to get automatic limits from data and I could also call it as plot_data(some_data,my_ymin, my_ymax), when i need to define the axis range manually