ModuleNotFoundError 'matplotlib_inline' - python

As the title suggests, I am trying to set my notebook to plot in separate window using the '%matplotlib qt' command. However, when I do I get a 'ModuleNotFoundError' for matplotlib.inline for some reason. I have checked my env using 'pip list' and I have all the modules I need installed (I know this is the case because I have other environments for separate projects where %matplotlib qt works just fine and the module imports are identical.
Hoping for a suggestion that I haven't tried yet. pic of my import cell on current notebook:
The problem seems to occur when I run the % command, even if I just run %matplotlib (without the qt) then I still get the same error. Could this be some sort of a path issue?
EDIT: I will add that if I remove the % command from my notebook I can plot just fine inline, but I don't have the plot tools to zoom in or move around which is the functionality I need to review my data.

Related

How to load Python script into Jupyter Notebook without revealing code and making it available to all cells

I'm trying to import a Python script as a module into one of my Notebooks, but the import or import importlib commands do not work in Jupyter Notebook like they do in a standard Python file and terminal.
I've come across the %load command but as far as I understand and have seen in my own Notebook, is that it only loads the contents of the script I'm trying to import into the current cell and is invisible to the other cells, and it also outputs the code in the script being imported for everyone to see.
I want to be able to load the script and make it available to all cells, as well as hiding the code for the purpose of encapsulation and also keeping the Notebook neat and tidy - only focusing on the code relevant to the topic of the Notebook. Is this possible?

Jupyter IPYNB Problems

so I'm trying to familiarize myself with the Jupyter Notebook and am running into issues.
When I run the following code in the normal .py file of my PyCharm IDE it runs perfect; however, if I run it in my notebook the [*] never disappears meaning it just continuously runs never ending. Any idea why that might be the case? all answers much appreciated!
import pandas as pd
train_file='C:\Users\DDautel\Anaconda2\PycharmProjects\Kaggle\Titanic\RUN.csv'
test_file='C:\Users\DDautel\Anaconda2\PycharmProjects\Kaggle\Titanic\RUN2.csv'
train=pd.read_csv(train_file)
test=pd.read_csv(test_file)
print train.describe()
print test.describe()
For others gratification:
Glad it's solved.
Make sure python, ipython, jupyter from anaconda (using conda env's possibly) is in your path before others. Order is important.

matplotlib plotting with python in xcode

I am trying to run python in XCode. The following simple plotting routine,
import matplotlib.pyplot as pyplot
pyplot.plot((0,1),(1,2))
pyplot.show()
returns no errors. XCode seems pretty happy with what it accomplishes when I hit the run button. But I get no plot window whatsoever, as far as I can tell. Is it hiding somewhere or what? How do I get to see it?
xcode will allow you to see plots if you move your code into an interactive notebook.
create a new file with the .ipynb file extension
copy your code into that file
You should be able not only to see the plots but also any other output your code is trying to send to the UI.

DataFrame.to_csv() not working in IPython notebook

After updating various packages (I'm running the Anaconda Python distribution) DataFrame.to_csv() will not work from within IPython Notebook. Everything else Pandas-related seems to work fine (reading data into datframes, manipulating them, etc.) but DataFrame.to_csv() will not generate an output file. A snippet of the code:
hives_output = hives_data.groupby(['user_id','replay']).apply(hives_processor).sort(['user_id','replay'])
hives_output.to_csv('hives_output.csv',index=False)
The first command runs fine, but no output file is produced by the second command. No error is produced whatsoever.
Weirder still, the code runs fine (i.e. it does generate an output file) within a regular Python or IPython interpreter, or when run from the command line, so the problem would seem to be specific to IPython Notebook.
I've tried downgrading various packages, but have yet to isolate the problem. Has anyone experienced this? Any ideas on what might be the cause? Some sort of incompatibility between IPython-Notebook and Pandas?

How do I load and run specific packages when I launch 'matplotlib'?

I see how to change certain settings for matplotlib in such a way that the are used to configure it each time I launch, including when I launch interactively with
ipython --pylab
but I'm not sure how run arbitrary code each time I launch in this way, or how to ensure that certain packages have been imported. For example I'd like to do the following whenever I launch as above:
from mpltools import style
style.use('ggplot')
How do I load and run specific packages when I launch 'matplotlib'?
From the ipython website it seems you can place any .py file in the startup folder of your profile and it will be run when ipython is initiated. For help finding the profile where your startup folder is [see here].
To get the effect your looking for you need to check that matplotlib has been imported, the only way I can think of doing that is to add the following
import sys
if "matplotlib" in sys.modules:
# Do something
print
print "This seems to be working"
I have left it with the test so you can quickly determine if it is working.
Two things to note: I am using ipython 2.0.0-dev (in case this has any bearing), and secondly I suspect that calling sys.modules is not recommended, or at least that was the impression I had off the SO post I borrowed the idea from, perhaps someone better than I can enlighten us.

Categories

Resources