Function which translates between matplotlib linestyle in short notation (i.e. ‘-‘, ‘–’, ‘:’, ‘-.’) and long notation (i.e. ‘solid’, ‘dashed’, ‘dotted’, ‘dashdot’ ).
If linestyle is none of these allowed options, the function raises a ValueError.
INPUT:
The linestyle can also be prefixed with a drawing style (e.g., "steps--")
If linestyle is None (of type NoneType), then we return it back unmodified.
return_type - The type of linestyle that should be output. This argument takes only two values - "long" or "short".
EXAMPLES:
Here is an example how to call this function:
sage: from sage.plot.misc import get_matplotlib_linestyle
sage: get_matplotlib_linestyle(':', return_type='short')
':'
sage: get_matplotlib_linestyle(':', return_type='long')
'dotted'
TESTS:
Make sure that if the input is already in the desired format, then it is unchanged:
sage: get_matplotlib_linestyle(':', 'short')
':'
Empty linestyles should be handled properly:
sage: get_matplotlib_linestyle("", 'short')
''
sage: get_matplotlib_linestyle("", 'long')
'None'
sage: get_matplotlib_linestyle(None, 'short') is None
True
Linestyles with "default" or "steps" in them should also be properly handled. For instance, matplotlib understands only the short version when "steps" is used:
sage: get_matplotlib_linestyle("default", "short")
''
sage: get_matplotlib_linestyle("steps--", "short")
'steps--'
sage: get_matplotlib_linestyle("steps-predashed", "long")
'steps-pre--'
Finally, raise error on invalid linestyles:
sage: get_matplotlib_linestyle("isthissage", "long")
Traceback (most recent call last):
...
ValueError: WARNING: Unrecognized linestyle 'isthissage'. Possible
linestyle options are:
{'solid', 'dashed', 'dotted', dashdot', 'None'}, respectively {'-',
'--', ':', '-.', ''}
Calculate the necessary parameters to construct a list of points, and make the functions fast_callable.
INPUT:
OUTPUT:
EXAMPLES:
sage: x,y,z=var('x,y,z')
sage: f(x,y)=x+y-z
sage: g(x,y)=x+y
sage: h(y)=-y
sage: sage.plot.misc.setup_for_eval_on_grid(f, [(0, 2),(1,3),(-4,1)], plot_points=5)
(<sage.ext...>, [(0.0, 2.0, 0.5), (1.0, 3.0, 0.5), (-4.0, 1.0, 1.25)])
sage: sage.plot.misc.setup_for_eval_on_grid([g,h], [(0, 2),(-1,1)], plot_points=5)
((<sage.ext...>, <sage.ext...>), [(0.0, 2.0, 0.5), (-1.0, 1.0, 0.5)])
sage: sage.plot.misc.setup_for_eval_on_grid([sin,cos], [(-1,1)], plot_points=9)
((<sage.ext...>, <sage.ext...>), [(-1.0, 1.0, 0.25)])
sage: sage.plot.misc.setup_for_eval_on_grid([lambda x: x^2,cos], [(-1,1)], plot_points=9)
((<function <lambda> ...>, <sage.ext...>), [(-1.0, 1.0, 0.25)])
sage: sage.plot.misc.setup_for_eval_on_grid([x+y], [(x,-1,1),(y,-2,2)])
((<sage.ext...>,), [(-1.0, 1.0, 2.0), (-2.0, 2.0, 4.0)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,-1,1),(y,-1,1)], plot_points=[4,9])
(<sage.ext...>, [(-1.0, 1.0, 0.6666666666666666), (-1.0, 1.0, 0.25)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,-1,1),(y,-1,1)], plot_points=[4,9,10])
Traceback (most recent call last):
...
ValueError: plot_points must be either an integer or a list of integers, one for each range
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(1,-1),(y,-1,1)], plot_points=[4,9,10])
Traceback (most recent call last):
...
ValueError: Some variable ranges specify variables while others do not
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(1,-1),(-1,1)], plot_points=5)
doctest:...: DeprecationWarning:
Unnamed ranges for more than one variable is deprecated and
will be removed from a future release of Sage; you can used
named ranges instead, like (x,0,2)
See http://trac.sagemath.org/7008 for details.
(<sage.ext...>, [(1.0, -1.0, 0.5), (-1.0, 1.0, 0.5)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], plot_points=5)
(<sage.ext...>, [(1.0, -1.0, 0.5), (-1.0, 1.0, 0.5)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(x,-1,1)], plot_points=5)
Traceback (most recent call last):
...
ValueError: range variables should be distinct, but there are duplicates
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,1),(y,-1,1)])
Traceback (most recent call last):
...
ValueError: plot start point and end point must be different
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(y,-1,1)], return_vars=True)
(<sage.ext...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [x, y])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], return_vars=True)
(<sage.ext...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [y, x])
Return a tuple of variables of the functions, as well as the number of “free” variables (i.e., variables that defined in a callable function).
INPUT:
OUTPUT: functions, expected arguments
EXAMPLES:
sage: x,y,z=var('x,y,z')
sage: f(x,y)=x+y-z
sage: g(x,y)=x+y
sage: h(y)=-y
sage: sage.plot.misc.unify_arguments((f,g,h))
((x, y, z), (z,))
sage: sage.plot.misc.unify_arguments((g,h))
((x, y), ())
sage: sage.plot.misc.unify_arguments((f,z))
((x, y, z), (z,))
sage: sage.plot.misc.unify_arguments((h,z))
((y, z), (z,))
sage: sage.plot.misc.unify_arguments((x+y,x-y))
((x, y), (x, y))