While trying to use LaTeX with IPython, I used the following code:
from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))
from How to write LaTeX in IPython Notebook?.
But, I got the following error.
<IPython.core.display.Math at 0x269a030>
What does this error mean? When do I get it? How can I get rid of it?
That is not an error. Run it with ipython notebook and you will see your integral displayed.
It is not an error, it is the output representation. Simply run the code inside the IPython notebook:
from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))
Related
I have learned how to display symbolic math in jupyter notebook using the display, Math, & Latex packages.
An example would be: display(Math('some math eqn')), which would result in clearly formatted symbolic math within jupyter notebook.
Now I am interested in exporting the display to an image file so I can use it elsewhere.
I tried using the code below, but it returned a NoneType object:
Image(display(Math('f(x) = x + 2C')), embed=True, format=PNG)
How would I go about doing this please?
Update:
I tried executing display(Math("\dfrac{5x}{3}")) via a cmd prompt and got this: <IPython.core.display.Math object>. I'm wondering if there's a way to convert this object type to an image?
I've been using a Jupyter notebook to print output in Markdown format with the IPython.display module, following the instructions here:
from IPython.display import display, Markdown
test_expression = '**blah** blah'
display(Markdown(test_expression))
When I execute that code block, I see the Markdown output as expected:
blah blah
But when I save, close and then reopen the notebook (without restarting the kernel), the same output is displayed incorrectly:
<IPython.core.display.Markdown object>
Should I use a different command to display the Markdown to ensure that it's consistent?
So I am having an issue when I try to save figures in Python.
If I create a figure f, and try to save it using the line
f.savefig('Test.eps', format='eps')
It yields yields the following error message :
TypeError: compile() expected string without null bytes.
It doesn't depend on the figure I want to save or on the format I choose, the error remains.
An example of a code I use could be :
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
A=np.array([1,2,3,4])
f=plt.figure(figsize=(13,11))
plt.plot(A)
f.savefig('Test.eps', format='eps')
which will yield :
TypeError: compile() expected string without null bytes.
Anyone knows where this might come from ?
Thanks
I tried your code and I had an error but I solved it by installing python-tk. After that, I execute correctly.
Are you sure you installed the packages correctly?.
This question is probably related to Unable plot with vincent in IPython , although I think it's not exactly the same problem.
I can plot a bar chart using Vincent 0.4.4 in an IPython 0.13.1 notebook as in the following example (found in the docs):
import vincent
vincent.core.initialize_notebook()
bar = vincent.Bar(multi_iter1['y1'])
bar.axis_titles(x='Index', y='Value')
bar.display()
However, I'm unable to do the same thing with the worldmap representation in the data mapping example:
import vincent
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'world-countries'}]
vis = vincent.Map(geo_data=geo_data, scale=200)
vis.to_json('vega.json')
I've replaced the value 'world_topo' with the path to the Topojson file (world-countries.topo.json) downloaded from here.
No errors are shown and nothing happens. I'm not using HTTPS, by the way. This is the simplest map chart example, so I guess it should work smoothly...
Any ideas?
Following the webpage of vincent an IPython version of >= 1.0 is required, thus, an upgrade to a more recent version (e.g. IPython 2.1) is very likely to solve your problem. On my ubuntu machine the map plot of vega works nicely.
Moreover, it is required to call the vis.display() method after the setup of the plots, as shown in e.g. this example notebook.
One thing I tried was to put the world map file in the directory of the Python script. Additionally remember to include
import json
vincent.core.initialize_notebook()
How do you get iPython to output results using latex?
For example, like on this page: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/master/examples/notebooks/SymPy%20Examples.ipynb
If I execute the code:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
I get output:
Out[13]: 3*pi/2 + exp(I*x)/(x**2 + y)
I want to see output in latex as shown in the link above.
An updated answer for those googlers:
from IPython.display import Math
Math('3 \cdot \\frac{\pi}{2} + e^{\\frac{I*x}{x^2 + y}}')
A bit more clumsy than SymPy, but doesn't need an extra package.
As done in the link you posted and mentioned by #tcaswell you need to "activate" the latex printing using
from sympy.interactive import printing
printing.init_printing(use_latex=True)
the use_latex=True statement is required with sympy 0.7.2 but not with 0.7.3.