Declarative interface to matplotlib

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Declarative interface to matplotlib

Ram Rachum
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Ryan May-3
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Ram Rachum
Thanks Ryan, that's interesting.

On Sun, Aug 23, 2020 at 10:31 PM Ryan May <[hidden email]> wrote:
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

tcaswell
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 <[hidden email]> wrote:
Thanks Ryan, that's interesting.

On Sun, Aug 23, 2020 at 10:31 PM Ryan May <[hidden email]> wrote:
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Thomas Caswell
[hidden email]

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Hannah
In reply to this post by Ram Rachum
If you want an out of the box decelerative API, plotnine is a ggplot API inspired wrapper over Matplotlib. https://plotnine.readthedocs.io/en/stable/

It also kind of stalled out, but their was some work on an mpl-altair backend to Altair so that you could use the Vegalite grammar and we'd support that project getting picked up again https://github.com/matplotlib/mpl-altair 

Like Tom said though, it may be cleaner to start w/ your usecase and build a declarative wrapper around that.

On Sun, Aug 23, 2020, 1:39 PM Ram Rachum <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Benjamin Root
In reply to this post by tcaswell
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 <[hidden email]> 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 <[hidden email]> wrote:
Thanks Ryan, that's interesting.

On Sun, Aug 23, 2020 at 10:31 PM Ryan May <[hidden email]> wrote:
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Thomas Caswell
[hidden email]
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Benjamin Root
jinx!

On Mon, Aug 24, 2020 at 12:14 AM Benjamin Root <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
Thanks Ryan, that's interesting.

On Sun, Aug 23, 2020 at 10:31 PM Ryan May <[hidden email]> wrote:
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Thomas Caswell
[hidden email]
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Declarative interface to matplotlib

Ram Rachum
Thanks for the answers guys!

On Mon, Aug 24, 2020 at 7:16 AM Benjamin Root <[hidden email]> wrote:
jinx!

On Mon, Aug 24, 2020 at 12:14 AM Benjamin Root <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
Thanks Ryan, that's interesting.

On Sun, Aug 23, 2020 at 10:31 PM Ryan May <[hidden email]> wrote:
Hi,

The MetPy project has worked on a declarative, matplotlib-based plotting interface:


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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Ryan May

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Thomas Caswell
[hidden email]
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users