enter code hereI am a beginner in jupyter and am trying to do symbolic computations using sympy.
after running the following code
%matplotlib inline
import sympy as s
s.init_printing()
from IPython.display import display_latex
theta=s.symbols('theta')
print(theta)
instead of getting the symbol for theta the output is "theta"
I can get latex display in markdown cell so I don't thins that this is a mathjax issue
I am using jupyterlab 3.0.14
I know this is a duplicate but implementing fixes other discussions didn't resolve my issue
Related
I use MikTeX and try to obtain LaTeX fonts in my matplotlib plots.
However, using the demo code, Jyputer Notebook says that there is no latex,
Failed to process string with tex because latex could not be found
I try to add into PATH the path to latex.exe, dvipng.exe and ghostscript. Unfortunately, it still does not work. What I do wrong?
If I evaluate the following
import matplotlib.pyplot as plt
import numpy as np
plt.plot(np.sin(np.arange(0, 10, 0.1)),label=r"$\mathcal{M}=2$")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
it returns me the next picture,
So, I see that \mathcal{} command works perfectly, whereas the fonts are not "latex".
You need to add plt.rc('text', usetex=True).
For years I have created figures using some rendition of the following code:
import pylab as pl
fig = pl.figure(figsize=(3.5, 2.5))
ax0 = fig.add_subplot(111)
Earlier this week I had to reinstall Python using the most-recent Anaconda Python 3.7 release (previous version was also 3.7). The problem is when I create my figure the figure window appears immediately (normally the figure window would never appear until I called fig.show()). I checked the matplotlib backend to see if it was different, but it is set to qt5agg. I don't think the backend is the problem. Does anyone know of a recent change in matplotlib that would cause the figures to pop up...anyone know how to prevent them from popping up without setting the backent to agg?
Current matplotlib version: 3.1.1
I tried:
import matplotlib.pyplot as plt
from latex import bm
plt.text(1, 1, "$\bm{q}$")
the error:
ImportError: cannot import name 'bm'
When I use it without from latex import bm it gives nothing and the colors in file are strange (b is black)
There are two issues here, one of which is simpler to fix than the other: the first issue is that the "\b" in your string literal will be interpreted as a Python-level string escape: "\b" is an ASCII backspace character, in the same way that "\t" is a tab character. You need to either escape the backslash so that it gets passed through to LaTeX, or use a raw string. So you need to replace "$\bm{q}$" with either r"$\bm{q}$" or "$\\bm{q}$".
The second issue is that by default, matplotlib's math rendering uses the mathtext library, which doesn't include support for the "\bm" control sequence. If you want to use LaTeX packages not included in mathtext, you can instruct matplotlib to use your local LaTeX installation to render mathematics, instead of using mathtext. You do that with, for example:
from matplotlib import pyplot as plt
plt.rcParams['text.usetex'] = True
Then you need to make sure that the bm package is being used. To do that, you need to change the LaTeX preamble that matplotlib uses:
plt.rcParams['text.latex.preamble'] = [r'\usepackage{bm}']
This does of course mean that you need to have a working LaTeX installation on your machine, and key executables (like latex, dvipng and kpsewhich) need to be on your PATH so that matplotlib can find them.
Once you've done all that, the rendering should work.
Here's a complete self-contained example:
from matplotlib import pyplot as plt
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = [r'\usepackage{bm}']
plt.plot([0, 1, 2])
plt.text(1.5, 1, r"$\bm{testing}$")
plt.show()
And here's the image I see when I run the above code on my system (which is equipped with the standard TeX Live installation):
I am trying to create a 3D scatter plot using matplotlib in a Jupyter Notebook page. The code is not returning any errors, but I have yet to have the plot actually show up. The output is just blank.
Python: 3.7.3
Matplotlib: 3.0.3
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
%matplotlib notebook
threedee = plt.figure().gca(projection='3d')
threedee.scatter(existing_df_2d.PC1, existing_df_2d.PC2,
existing_df_2d.data_mean)
plt.show()
I included an example of the output (it's blank):
You are using two backends
%matplotlib inline
%matplotlib notebook
As a result, there seems to be a conflict between the two backends when invoked in parallel one after the other.
P.S: When I tried putting %matplotlib notebook in the same cell as the rest of the code, I did not see any figure. When I put it in a different cell, I see the figure.
Solution: Just use either the %matplotlib inline or %matplotlib notebook in a new separate cell and things will work fine
In my experience, %matplotlib notebook doesn't work with 3D plots unfortunately. Just use %matplotlib inline and you should be OK.
I want to get the color of pixels on the screen in Python3.x. (example x,y)
I work on windows. and using tkinter.
But, It can't use PIL in Python 3.x.
How can i do this.
Thank you.
You can use PIL on Python3.x; there is a binary installer for Windows. The code might not work as is both on Python2.x and Python3.x:
try: import Image # Python 2.x
except ImportError:
from PIL import Image # Python 3.x
You could capture an area of the screen using an analog of grab() method.