matplotlib rc('text', usetex=True) breaks plotting from .ipynb to .py (jupyter --> spyder)
See original GitHub issueDescription of your problem
I loaded a .py file from jupyter to use it in spyder. But the plotting does not work anymore. I narrowed it down to the rc(‘text’, usetex=True) command. I asked this on stackoverflow:
Original Question: http://stackoverflow.com/questions/40266888/migrating-jupyter-notebook-to-py-file-spyder-basic-plotting-is-killed-by-late
What steps will reproduce the problem?
create a .py script in spyder:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.gridspec as gs
from matplotlib import rc # this is the matplotlib suggestion
rc('font',**{'family':'sans-serif','sans-serif':['Arial']})
rc('text', usetex=True)
mat = np.random.rand(5,5)
fig = plt.figure()
gsall = gs.GridSpec(6, 1)
ax1 = fig.add_subplot(gsall[:])
source1 = ax1.contourf(mat,extend='both',cmap=mpl.cm.viridis)
plt.title('Random field \n test')
plt.colorbar(source1)
plt.show()
run it.
What is the expected output? What do you see instead?
I expect a figure with the random matrix and the text, but I get many errors.
Please provide any additional information below
In jupyter notebook everything is fine. In ipython shell I get a figure without the text and no errors.
Versions and main components
- Spyder Version: 2.3.9
- Python Version: 3.5.1
- Operating system: macOS sierra v.10.12.1
- Matplotlib Version: 1.5.1
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Migrating jupyter notebook to .py file (spyder) basic plotting is ...
I am using Anaconda with python 3.5 on a mac with os sierra. I have an extensive script with several plot commands from...
Read more >Convert Jupyter Notebook to Python script in 3 ways - MLJAR
Convert Jupyter Notebook to Python script Jupyter Notebook saves files in .ipynb format. It is a JSON with code, Markdown, and outputs.
Read more >Interactive figures — Matplotlib 3.6.2 documentation
The pyplot module provides functions for explicitly creating figures that include interactive tools ... We recommend using IPython for an interactive shell.
Read more >Built-in magic commands — IPython 8.7.0 documentation
If you are looking for an IPython version compatible with Python 2.7, ... In particular, running the command 'history -f FILENAME' from the...
Read more >Python Cheatsheet - Basic Syntax and Usage
Jupyter Notebooks have the file extension ipynb, e.g. Python-Tutorial.ipynb. If you open an *.ipynb file with a simple text editor such as Notepad++, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ImportanceOfBeingErnest, if you define or extend
PATH
in your.bashrc
and don’t start Spyder in a console but using a graphical menu or launcher, then Spyder is unable to detect those modifications toPATH
because it doesn’t read your environment variables before launching. By the way, Pycharm also has this problem, as reported here:https://stackoverflow.com/a/9706384/438386
And I think the same happens in the Jupyter notebook. I mean, I haven’t seen any code to read env vars in Jupyter or IPython. But the problem could be alleviated there because you usually start the notebook server in a console, and so their environment is picked up by the kernels started by it.
To summarize, I don’t know if you could say this is a Spyder problem or people not knowing how env vars work.
Hi @louika
I think you only need:
for you can to reproduce this example over Ipython console without problems with your actual anaconda environment.
I hope this help you.