From: Benjamin R. <ben...@ou...> - 2013-10-25 13:34:45
|
Daniele, On Fri, Oct 25, 2013 at 8:45 AM, Daniele Nicolodi <da...@gr...>wrote: > On 24/10/2013 21:26, Paul Ivanov wrote: > > One quick reply: > > > > Daniele Nicolodi, on 2013-10-24 21:03, wrote: > >> One thing I dislike is, for example, the add_subplot() method: > >> > >> f = plt.figure() > >> a = f.add_subplot(111) > >> a.plot(x, y) > >> > >> it feels completely out of place (why I need to add a subplot if the > >> only thing I want to do is to create a figure with a single plot in it?) > >> and kind of magic (what is the number 111?). > > > > f, a = plt.subplots() > > a.plot(x, y) > > That's better, however to create _sub_ plots to have a single plot into > a figure still feels weird, It doesn't feel weird. It feels generalized. It is the same way to add any number of plots, regardless if it is just one, or twenty. If you don't want to do it that way, you can just simply do: fig = plt.figure() ax = fig.gca() # "get current axes" automatically creates an axes if one doesn't exist already You also have http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.add_axes > also I would expect it to be a method of the > Figure class and not a top level function. It does: http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.add_subplot This is *the* function that does axes creation for a figure, whether it is one, or many. > Furthermore, most > documentation refers to add_subplot() and not subplots() which has a > more understandable function signature. > > subplots() is a recent addition. We are in the process of updating our documentation. But add_subplot() is not going away because it works just fine, and it is very familiar to users of Matlab and Octave. > In principle I think the current API violates the "There should be one-- > and preferably only one --obvious way to do it" rule here, and elsewhere > :-) > > I feel the way forward should be to create a cleaner API and map the > current one through a compatibility layer to that. > > This has already been done. We have the GridSpec API that everything else maps to, for compatibility. But most people still like add_subplot() and subplots() for some odd reason... I think the primary issue is one of documentation, and we are currently in the process of upgrading that. We always welcome contributions to that effort! Cheers! Ben Root |