Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on the version of SymPy that you are using.</p> <p>In the latest version (0.7.2) you already have a plotting module that is guaranteed to be able to plot <em>anything</em> and that can use as a backend matplotlib.</p> <p>In older versions you have the option to use <code>lambdify</code> which is a hackish, mostly broken helper function that returns a fast numerical function to be used with numpy. However it breaks for non-trivial expressions.</p> <p>Below I explain how to use the plotting module in 0.7.2:</p> <ol> <li>Just call <code>plot</code> like in <code>p = plot(expression, (var, start, stop))</code>. If you have <code>matplotlib</code> it will use it directly.</li> <li>If you want something fancy, extract the <code>matplotlib</code> figure: <code>f = p._backend.fig</code>.</li> <li>Stop caring about SymPy, the rest of your work is in <code>matplotlib</code>. You can do whatever you want.</li> </ol> <p>The idea behind SymPy's plotting module is to be able to evaluate any possible expression, not to reimplement a plotting library like matplotlib. So just use <code>sympy.plotting.plot</code> for evaluation and do the fancy subplot transformations in matplotlib.</p> <p>Using the sympy plotting module has other advantages over hackish solutions: detection of discontinuities and adaptive sampling, coloring depending on a function, evaluation of pathologically complicated symbolic expressions (although slow).</p> <p>And obviously, check the docs. While they are not great, many questions are answered there: <a href="http://docs.sympy.org/0.7.2/modules/plotting.html">http://docs.sympy.org/0.7.2/modules/plotting.html</a> Check also the notebooks in the example folder of sympy.</p> <p>EDIT to address some additional questions:</p> <ol> <li><p>There is no notion of subplots in the SymPy's plotting module, and hopefully there will never be one. As I mentioned above, SymPy is not trying to reimplement modules like <code>matplotlib</code>, rather it is trying to give the tools necessary for good easy use within another module (interfaces between modules are better than big project with many small submodules).</p></li> <li><p>In order to create one figure with two subplots in matplotlib from two different sympy plots do (this is an ugly hack, as matplotlib does not support merges of figures):</p> <pre><code>sympy_p1 = sympy.plot(foo) sympy_p2 = sympy.plot(bar) matplotlib_fig = plt.figure() sp1 = matplotlib_fig.add_subplot(121) sp2 = matplotlib_fig.add_subplot(122) sp1.add_collection(sympy_p1._backend.ax.get_children()[appropriate_index]) sp2.add_collection(sympy_p2._backend.ax.get_children()[appropriate_index]) matplotlib_fig.show() </code></pre></li> <li><p>In order to update sympy plot (not creation of a subplot, just adding a new expression) use <code>sympy_p1.append(sympy_p2)</code>. This will result in <code>sympy_p1</code> containing the plots of both <code>foo</code> and <code>bar</code> (<strong>NOT</strong> two subplots, rather one plot with both expressions).</p></li> <li><p>You might want to use <code>sympy.plot(..., show=False)</code> in some cases.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload