You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[ENH]: callable arguments to the high level plot functions #20926
It would be convenient if .plot and similar high level plotting routines identified callable arguments and if possible evaluated those with array arguments. I imagine the amount of meaningful combinations would be limited.
Additional context and prior art
Providing functions as input to plotting routines and letting those take care of the evaluation is a common pattern.
Specifically in the case of defining a grid for x and evaluating a function for y* (arguably the only case where automatically evaluating a function would make sense, too), you can use the walrus operator:
plt.plot(x:=np.linspace(xmin, xmax), f(x))
*Should clarify: you could user keyword arguments to rearrange things so that whatever variable you're defining the grid on comes first:
We have had at least 2 attempts to add fplot (#1143 and #737) but if I recall correctly they got bogged down in the numerics / theory of how to smartly sample around shape peaks.
If this is something you do all the time, I suggest putting something like
For plotting to feel "fluid" it the API needs to be closely tuned to your needs and data, which means the API needs to be opinionated and bake a lot of assumptions in. While there are some cases (like seaborn) where this can be done across a pretty big domain, I think all users should embrace writing mini-libraries exactly tuned to their needs (exactly like we all do with analysis)!
It might also be worth looking at sympy which has a plotting layer that understands sympy objects and "does the right thing" in many cases.
Enabling this sort of thing more generally is one of the goals of @story645 's thesis work. By pulling all of the data management into a dedicated class (rather than stored ad-hoc on the Arstist as now), we will be able to at draw-time query that object with the current view limits (in data space) and axes size (in screen space) to get the relevant data. This will enable things like smart (re-)sampling of the underlying data to be injected into all Matplotlib artists (rather than having to live in the Artist implementation).
I was thinking that with AI and modern algorithms could possible made an advancement in like age progression photography.--Sent from my Android phone with mail.com Mail. Please excuse my brevity.On 8/28/21, 12:50 PM Thomas A Caswell ***@***.***> wrote:
We have had at least 2 attempts to add fplot (#1143 and #737) but if I recall correctly they got bogged down in the numerics / theory of how to smartly sample around shape peaks.
If this is something you do all the time, I suggest putting something like
def my_cleverly_named_plotting_of_functions_function(x, f, *, ax=None, **kwargs):
if ax is None:
import matplotlib.pyplot as plt
ax = plt.gca()
return ax.plot(x, f(x), **kwargs)
in a local library.
For plotting to feel "fluid" it the API needs to be closely tuned to your needs and data, which means the API needs to be opinionated and bake a lot of assumptions in. While there are some cases (like seaborn) where this can be done across a pretty big domain, I think all users should embrace writing mini-libraries exactly tuned to their needs (exactly like we all do with analysis)!
It might also be worth looking at sympy which has a plotting layer that understands sympy objects and "does the right thing" in many cases.
Enabling this sort of thing more generally is one of the goals of @story645 's thesis work. By pulling all of the data management into a dedicated class (rather than stored ad-hoc on the Arstist as now), we will be able to at draw-time query that object with the current view limits (in data space) and axes size (in screen space) to get the relevant data. This will enable things like smart (re-)sampling of the underlying data to be injected into all Matplotlib artists (rather than having to live in the Artist implementation).
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or unsubscribe.
Activity
mwaskom commentedon Aug 28, 2021
Specifically in the case of defining a grid for
xand evaluating a function fory* (arguably the only case where automatically evaluating a function would make sense, too), you can use the walrus operator:*Should clarify: you could user keyword arguments to rearrange things so that whatever variable you're defining the grid on comes first:
But
plt.plotdoes not take keyword arguments for x/y.akhmerov commentedon Aug 28, 2021
Great idea! This should indeed cover most of the relevant use cases.
tacaswell commentedon Aug 28, 2021
We have had at least 2 attempts to add
fplot(#1143 and #737) but if I recall correctly they got bogged down in the numerics / theory of how to smartly sample around shape peaks.If this is something you do all the time, I suggest putting something like
in a local library.
For plotting to feel "fluid" it the API needs to be closely tuned to your needs and data, which means the API needs to be opinionated and bake a lot of assumptions in. While there are some cases (like seaborn) where this can be done across a pretty big domain, I think all users should embrace writing mini-libraries exactly tuned to their needs (exactly like we all do with analysis)!
It might also be worth looking at sympy which has a plotting layer that understands sympy objects and "does the right thing" in many cases.
Enabling this sort of thing more generally is one of the goals of @story645 's thesis work. By pulling all of the data management into a dedicated class (rather than stored ad-hoc on the Arstist as now), we will be able to at draw-time query that object with the current view limits (in data space) and axes size (in screen space) to get the relevant data. This will enable things like smart (re-)sampling of the underlying data to be injected into all Matplotlib artists (rather than having to live in the Artist implementation).
Zero21102 commentedon Aug 28, 2021