[Matplotlib-users] Declarative interface to matplotlib

Benjamin Root ben.v.root at gmail.com
Mon Aug 24 00:15:32 EDT 2020


jinx!

On Mon, Aug 24, 2020 at 12:14 AM Benjamin Root <ben.v.root at gmail.com> wrote:

> Isn't Altair trying to be a declarative interface to matplotlib?
>
> Also, I could have sworn someone made a ggplot clone using matplotlib as a
> base?
>
> Ben Root
>
>
> On Sun, Aug 23, 2020 at 9:30 PM Thomas Caswell <tcaswell at gmail.com> wrote:
>
>> I think declarative APIs can be very terse if they are well tuned for a
>> given domain, however as you expand them to cover the general case it is
>> not clear to me that you will be able to preserve that terseness.
>>
>> Put another way, there is some inherent complexity in making a plot.  An
>> imperative API can rely on the host language (Python) to handle some of
>> that complexity whereas a declarative API must absorb all of the
>> complexity.  Either it will grow to be as complex as a programming language
>> or it will have to restrict its users to the vocabulary that the original
>> developers imagined.  On the other hand, if the declarative API matches
>> what you need (it makes all the right assumptions for your task and data)
>> it can be great!
>>
>> If you are finding yourself doing the same 10 things every time, I
>> suggest putting that into a function and eventually growing that into a
>> library / declarative API that is tuned to your data / domain / use.
>>
>> Tom
>>
>> On Sun, Aug 23, 2020 at 3:59 PM Ram Rachum <ram at rachum.com> wrote:
>>
>>> Thanks Ryan, that's interesting.
>>>
>>> On Sun, Aug 23, 2020 at 10:31 PM Ryan May <rmay31 at gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> The MetPy project has worked on a declarative, matplotlib-based
>>>> plotting interface:
>>>>
>>>>   https://unidata.github.io/MetPy/latest/examples/index.html#plotting
>>>>   https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.html
>>>>
>>>> https://unidata.github.io/python-training/gallery/declarative_500_hpa/
>>>>
>>>> This focuses, though, on domain-specific applications in meteorology
>>>> and atmospheric science, leveraging the traitlets library. The interface
>>>> was also designed to facilitate transition away from a legacy,
>>>> declarative-like plotting tool.
>>>>
>>>> Not claiming by any means we have the interface perfect. We spent a lot
>>>> of time trying to come up with new names for Figure and Axes in this
>>>> interface since we did not want to collide with matplotlib's own classes.
>>>> Honestly, the basic interface is pretty trivial to create (at least using
>>>> traitlets). The challenge is to handle state update and invalidation
>>>> properly when trying to support interactive use cases (especially when all
>>>> of the classes are thin wrappers around matplotlib state).
>>>>
>>>> Ryan
>>>>
>>>> On Sun, Aug 23, 2020 at 11:39 AM Ram Rachum <ram at rachum.com> wrote:
>>>>
>>>>> Hi everyone,
>>>>>
>>>>> I'd like to ask you a general question, as someone who isn't very
>>>>> experienced with matplotlib.
>>>>>
>>>>> I noticed that matplotlib is very imperative, in contrast to
>>>>> declarative. For example, I wanted to show an `imshow` plot with a
>>>>> colorbar, so I needed to first create the plot, then run `plt.colorbar()`,
>>>>> then show the plot. In more complicated plots, you could be doing 10+
>>>>> actions one after another to create a plot.
>>>>>
>>>>> I would find a declarative interface to be much more elegant, i.e. one
>>>>> call to create the plot and lots of keyword arguments, some of them nested,
>>>>> to specify all the options. Of course, matplotlib being a very mature
>>>>> project, the current interface must be maintained forever. But, do you know
>>>>> of any such declarative interface to matplotlib? Either as part of the
>>>>> library, or a separate library that uses matplotlib?
>>>>>
>>>>> If such a thing doesn't exist, what would you think about adding one?
>>>>>
>>>>>
>>>>> Thanks,
>>>>> Ram.
>>>>> _______________________________________________
>>>>> Matplotlib-users mailing list
>>>>> Matplotlib-users at python.org
>>>>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>>>>
>>>>
>>>>
>>>> --
>>>> Ryan May
>>>>
>>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Matplotlib-users at python.org
>>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>>
>>
>>
>> --
>> Thomas Caswell
>> tcaswell at gmail.com
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200824/d108b752/attachment-0001.html>


More information about the Matplotlib-users mailing list