In Spyder 2 (Anaconda distribution) and in the IPython QT Console I'm able to print results of symbolic calculations (from an answer I got for a previous post) but I can't get equations in strings to print with the a IPython's Rich Display System:
from sympy import *
from IPython.display import display, Math
init_printing(use_unicode=False, wrap_line=False, no_global=True)
x, y, z = symbols('x y z')
#----- prints correctly
ii = integrate(x**2 + x + 1, x)
display(ii)
#----- does not print
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
The above prints the results of the integrate correctly but the Math() does not print (no error -- just skips it). Note it all works in SciPy web notebook.
Thank you!
The Math class doesn't generate the rendered image from your Latex, that's why it doesn't work directly.
To get what you want you need to use this code
from IPython.display import Image, display
from IPython.lib.latextools import latex_to_png
eq = r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'
data = latex_to_png(eq, wrap=True)
display(Image(data=data))
Then you will see the right image
Hello guys im still having the problem, whe i use
from IPython.display import display, Math, Latex
display((Math(r'P(Purchase|Male)= \frac{Numero\ total\ de\ compras\ hechas\ por\ hombres\}{Total\ de\ hombres\ en\ el\ grupo\} = \frac{Purchase\cap Male}{Male}')))
on jupyter it works fine, but when i do the exact same code on spyder it doesnt work
im using python 3.6 , spyder 3.3.3
also i tried the marked asnwer but latex_to_png makes a NoneType Object on spyder
Related
I am using Jupyter in a Conda environment:
import igl
import meshplot as mp
import numpy as np
v, f = igl.read_triangle_mesh("./earth.ply")
k = igl.gaussian_curvature(v, f)
mp.plot(v, f, k, return_plot = True)
OUTPUT:
<meshplot.Viewer.Viewer at 0x1b53eb03fa0>
it is not displaying the mesh. it just outputs the location it stored in memory. Please help me.
It seems that you have your meshplot.rendertype set to "OFFLINE".
If you are using this code in a jupyter notebook and want to display the mesh, then just switch rendertype to "JUPYTER", by executing mp.jupyter() somewhere before your plot() command.
If you are running the code as a normal python program, you can export this View object as a HTML frame using the View.to_html() method. Then you can insert this frame into a html file and view it in a browser.
You can check out the source code for switching rendertype here, how the mp.plot function works here. The View class with the to_html method is defined here.
this command output latex in online Env
solve(x**2 - 33*x + 20*13-14**2, x)
same command outputs a plaintext on my local Env.
a simpler one could be rendered successfully.
did I missing something?
You need to initiate session first by calling init_session()
If you plan to work in an interactive calculator-type session, the init_session() function will automatically import everything in SymPy, create some common Symbols, setup plotting, and run init_printing()
from sympy import init_session
init_session()
x = 5
solve(x**2 - 33*x + 20*13 - 14**2, x)
I am trying to automatically convert an SVG graphic to EMF with Python, using Inkscape on the command line. My code is
from subprocess import call
import matplotlib.pyplot as plt
from numpy import linspace, sin
x = linspace(0,10,10)
y = sin(x)
plt.plot(x,y)
plt.savefig("source.svg")
for k in range(0,5):
call(["C:\Program Files\Inkscape\inkscape.exe", "--file", "source.svg", "--export-emf", "result" + str(k) + ".emf" ])
# this usually breaks down at k = 1 or 2
The "call" command works fine when called once. If I call it multiple times, e.g. on consecutive lines as shown above, Inkscape breaks down and I have to restart my python kernel and kill Inkscape via the Windows Task-Manager.
Any ideas why that might be?
Thanks!
ok, I know how to use init_printing to get sympy to automatically render IPython output using MathJax.
from sympy import init_printing
init_printing()
How do I get it to stop? (Yeah, I could reset my notebook but I'd like to turn it on just for a few cells and turn it off again.)
found it (had to UTSL):
sympy.init_printing(pretty_print=False)
When I run this simple code:
from pylab import *
import numpy as np
X = [];
Y = [];
for i in range (0,10):
X.append(i)
Y.append(i)
plot(X,Y)
show()
I don't get any window. I tried to replace show with draw with the same result.
I'm using python version 3.2.2
How can I show the window/plot than (apart from printing it to file and open the file).
Note, I'm using this example:
http://matplotlib.sourceforge.net/examples/api/custom_scale_example.html
I don't think numpy or scipy have a stable release for 3.2 yet.
Unless it's important to you that you use python 3.2, try to install python 2.7 instead. Everything should work fine there.