w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to get matplotlib working under IPython?
In my Python setup (2.7.3, Linux), I installed matplotlib as well as IPython via pip. matplotlib is available from the normal Python interpreter as well as from IPython (as expected). The order of installation does not matter. And no, IPython should not have matplotlib installed by default, this does not make sense.

Categories : Python

latex failure ipython daft matplotlib
In my case it was a LaTex library that needed to be installed (sorry I didn't pay attention to which one) It automatically opened my MikTex installer, so you install the suggested library and you should be done. There is no need for 'lp' to be accessible from the command line.

Categories : Python

Why is matplotlib plot produced from ipython notebook slightly different from terminal version?
The font size issues are due to differences in the dpi. I'd guess the slightly different size of the figure (in pixels) changes the "best" location for the legend, as well. The default dpi a figure is displayed at is 80, while savefig defaults to 100. This means that by default, matplotlib figures will look slightly different when saved compared to what's displayed on the screen. I don't know for sure, but I'm guessing that ipython notebooks set the dpi to something other than 100 (most likely 80) and use that when saving figures. Try doing savefig('filename.pdf', dpi=80) in your standalone script.

Categories : Python

IPython Kernel Non-Responsive: Running a Django development server from an IPython Notebook
I opened up an issue on IPython dev's github. Minrk found this solution: import subprocess server = subprocess.Popen(["python", "manage.py", "runserver"]) it allows me to view the dev server and continue to develop it in the IPython Notebook. sweet!

Categories : Django

IPython does not allow editing r when invoked as `ipython console`
From comments by @Thomas K This is a known issue https://github.com/ipython/ipython/issues/3030 %edit feature does not work in two process model.

Categories : Python

running PCA analysis matplotlib results print
If you look at the documentation for matplotlib.mlab.PCA you see from the header class matplotlib.mlab.PCA(a) that it is actually a class you are dealing with. When you do PCA(x) you are creating an instance of that class, and when you print it in the following line you are told that you have got yourself an instance of matplotlib.mlab.PCA. You can confirm this by printing the output of dir(results), where you'll see what attributes you have on the object. It can helpful to determine what object you are dealing with. What you want to do here is to use the attributes of this object you've got. For instance, print results.Y # print the projection in PCA space

Categories : Python

Convert matplotlib AxesImage to PIL PhotoImage, how to plot a matplotlib result in Tkinter
You have to create and empty ImageTk.PhotoImage instance, and then paste the content from your Image instance there. If you are reading from an AxesImage object (returned by imshow), you can transfer its data to Image first, then paste to PhotoImage. Here is an example (note that you actually need to compute myarray over a meshgrid): from Tkinter import * from PIL import Image, ImageTk import numpy as np import matplotlib.pyplot as plt from matplotlib import cm root=Tk() canvas = Canvas(root) canvas.pack(expand = YES, fill = BOTH) x = np.linspace(0, 2*np.pi, 400) y = np.linspace(0, 2*np.pi, 400) X, Y = np.meshgrid(x, y, copy=False) myarray = np.cos(X) + np.cos(Y) im_plt = plt.imshow(myarray) image1 = Image.fromarray(np.uint8( im_plt.get_cmap()(im_plt.get_array())*255)) im = ImageTk.Ph

Categories : Python

Embedding the matplotlib toolbar in pyqt4 using matplotlib custom widget
Ok, after more fiddling around and looking at link, I modified the class MplWidget to: class MplWidget(QtGui.QWidget): def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.canvas = MplCanvas() self.mpl_toolbar = NavigationToolbar(self.canvas, self) self.vbl = QtGui.QVBoxLayout() self.vbl.addWidget(self.canvas) self.vbl.addWidget(self.mpl_toolbar) self.setLayout(self.vbl) And now it works. Thanks!

Categories : Python

matplotlib: figlegend legend is empty box after upgrade to matplotlib 1.1.x
This behaves as expected: ax = gca() plot(range(15), label='test') h, l = ax.get_legend_handles_labels() figlegend(h, l, 'upper center') on master. Something else is broken in your code, I suspect legText.append(a.axesLegend) that line

Categories : Python

matplotlib figure opened but matplotlib window "not responding"
In matplotlib you need to use "plt.show()" to display the plot. Since you are using "plt.draw()" to update the plot, you probably also want to use the interactive mode. Try including this after your "ciz,=plt.plot([],[])" command: plt.ion() plt.show()

Categories : Python

Installing anaconda to use with windows
well you might have two installations of python, one inside the anaconda package, and other which you might have installed earlier. try doing : which python from CygWin console. If it returns: /usr/bin then it is definitely a add-to-path problem. to fix it for CygWin, you have to add the python installation from anaconda to the path. try this fromn CygWin: PATH=path-where-anaconda-is-installed/anaconda/bin:$PATH and then doing: which python should give you: /path-to-anaconda/anaconda/bin and then it will work. Cheers

Categories : Python

Anaconda default directory
Double your backslashes. pd.read_csv('C:\Users\aaa\Desktop\contrylist.csv') Or use raw strings: pd.read_csv(r'C:UsersaaaDesktopcontrylist.csv') Backslash is a special character in string literals and it's used for escaping. You should read the docs: strings and string literals.

Categories : Python

Pyqtgraph with anaconda python on MAC gives nib error
The solution is to use python.app (or the equivalent pythonw) to run the program, instead of just python. If pyqtgraph installed any commands, you'll need to edit them so that their shebang line calls #!/path/to/anaconda/bin/python.app/Contents/MacOS/python.

Categories : Python

Aligning markers for individual points in matplotlib and removing "double" legend for markers in matplotlib in Python
You have to provide the plot method with x-coordinate arguments. If given only one list-like object, matplotlib will use this list as the y-coordinates and use x = np.arange(len(y)) (where y are the given y-coordinates). You should not call the legend method several times for each Axes; include the numpoints kwarg in your original legend call. In other words, replace the lines lines_1=par1.plot(perform_1,linestyle='', marker='H', markerfacecolor ='k') lines_2=par1.plot(perform_2,linestyle='', marker='*',markerfacecolor ='m') ax.legend((rects1[0], rects2[0],lines_1[0],lines_2[0]), ('Current time period', 'Next time Period','Current Period Performance', 'Next Period Performance'),prop=dict(size=10) ) with lines_1=par1.plot(ind + 0.5*width, perform_1,linestyle='', marker='H', markerfac

Categories : Python

How to override anaconda/kickstart package ordering?
Your package "thirdparty-tools" needs to specify all of its requirements. If you can get a SRPM of this package, you can modify the spec to indicate that you need coreutils, bash, etc in your package. If you can't modify this package at all, your best option is to create a wrapper package that has the necessary requirements. Just use your favorite editor to create a file "thirdparty-tools-installer.spec" and ensure you include coreutils as a requirement as well as "thirdparty-tools". You can refer to rpm.or for more information http://www.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html Lastly, you can just do yum -y install thirdparty-tools in the %post section of Kickstart. It's uglier for sure, but it will probably work.

Categories : Linux

How to keep track of pip installed packages in an Anaconda (conda) env?
conda will only keep track of the packages it installed. And pip will give you the packages that were either installed using the pip installer itself or they used setuptools in their setup.py so conda build generated the egg information. So you have basically three options. You can take the union of the conda list and pip freeze and manage packages that were installed using conda (that show in the conda list) with the conda package manager and the ones that are installed with pip (that show in pip freeze but not in conda list) with pip. Install in your environment only the python, pip and distribute packages and manage everything with pip. (This is not that trivial if you're on Windows...) Build your own conda packages, and manage everything with conda. I would personally recommend the

Categories : Python

pip install lxml and gdal failing in anaconda env
Here is my $0.02, in my experience lxml installs on OS X have always caused problems because of the libmxl2 and libxslt dependencies. The specific issue here is that the 'cpl_port.h' is not being found suggesting that you don't have the headers for gdal on your system, a similar issue to the one I've encountered with lxml. I found this StackExchange post gdal package missing which addresses building and installing gdal with your specific error using pip and a virtual Ubuntu machine, but the idea is the same. The pip tool need to be told explicitly where to find the headers for gdal. In general the issue is that OS X puts headers in non standard places for a *nix system, and quite often dependencies are several revision behind the version used for development of the packages you are trying

Categories : Python

cannot import numpy in idle (2.7) after anaconda installation
So you have several python installations going; which one is idle using? This should get you pointed in the correct direction for finding modules: http://docs.python.org/release/2.7.5/tutorial/modules.html#the-module-search-path (Tweak the version number in that URL as appropriate.) If that doesn't help, then the list of Related questions, to the right, currently has this as the first hit, and it looks useful too.

Categories : Python

Anaconda's NumbaPro CUDA Assertion Error
The problem is you are using vectorize on a function that takes non-scalar arguments. The idea with NumbaPro's vectorize is that it takes a scalar function as input, and generates a function that applies the scalar operation in parallel to all the elements of a vector. See the NumbaPro documentation. Your function takes a matrix and a vector, which are definitely not scalar. [Edit] You can do what you want on the GPU using either NumbaPro's wrapper for cuBLAS, or by writing your own simple kernel function. Here's an example that demonstrates both. Note will need NumbaPro 0.12.2 or later (just released as of this edit). from numbapro import jit, cuda from numba import float32 import numbapro.cudalib.cublas as cublas import numpy as np from timeit import default_timer as timer def gener

Categories : Python

Importing scipy.misc.pilutil in python using Komodo and Anaconda?
The problem is that the scipy.misc.__init__ deletes the pilutil module - relevant code line - so you cannot import it directly. But all functions from the pilutil module are, before that, added to the misc module, and you can use them from there: In [1]: from scipy import misc In [2]: misc.fromimage Out[2]: <function scipy.misc.pilutil.fromimage> In [3]: misc.bytescale Out[3]: <function scipy.misc.pilutil.bytescale>

Categories : Python

Anaconda: Where and how to install a non-distribution package to support a flask-wtf conda recipe?
The only way that conda build will see dependencies is if they also exist as conda packages. So you need to build the conda package for wtforms as well. Fortunately, the recipe for this exists in the conda-recipes as well, so you can just clone that repo and do conda build wtforms conda build flask This works because conda is able to find the packages that it has already built. To make sure that they don't get lost if you delete the build directory, it's recommended to upload your packages to Binstar. If you do that and conda install binstar, after you build, it will ask you if you want to upload the package to binstar. If you do that, and also add your Binstar repo to your .condarc, those packages will always be available for you to conda install.

Categories : Python

Remove and Re-Add Object in matplotlib | Toggle Object appearance matplotlib
You want set_visible (doc) an = gca().annotate('TEST', xy=(.1, .1), xytext=(.1 + 15,.1), arrowprops=dict(facecolor='#404040')) gca().set_xlim([0, 30]) draw() plt.pause(5) an.set_visible(False) draw() plt.pause(5) an.set_visible(True) draw()

Categories : Python

IPython and __doc__
As @Blender says, __doc__ is just a string, and is usually the help string for a given function or module. For example, In [1]: numpy.__doc__ Out[1]: ' NumPy ===== Provides 1. An array object of arbitrary homogeneous items 2. Fast mathematical operations over arrays ... is the help string for the numpy module. Calling help() on numpy essentially just prints out a nicely formatted version of this string: Help on package numpy: NAME numpy FILE /usr/lib64/python2.6/site-packages/numpy/__init__.py DESCRIPTION NumPy ===== Provides 1. An array object of arbitrary homogeneous items 2. Fast mathematical operations over arrays ... In IPython, the string __doc__ is just: In [3]: __doc__ Out[3]: 'Automatically created module for IPython interact

Categories : Python

Is there a IPython notebook api?
There is, you can do: import io from IPython.nbformat import current def convert(py_file, ipynb_file): with io.open(py_file, 'r', encoding='utf-8') as f: notebook = current.reads(f.read(), format='py') with io.open(ipynb_file, 'w', encoding='utf-8') as f: current.write(notebook, f, format='ipynb') convert('test.py', 'test.ipynb') But it's not that smart and it will place all the code from the python file into one IPython Notebook cell. But you can always do a little bit of parsing. import io import re from IPython.nbformat import current def parse_into_cells(py_file): with io.open(py_file, 'r', encoding='utf-8') as f: data = f.readlines() in_cell = True cell = '' for line in data: if line.rstrip() == '': # If a blan

Categories : Python

Import from ipython
is your PYTHONPATH different in ipython and IDLE? try the following import sys print(sys.path) I suspect the two won't match. have you launched IDLE and ipython from the same terminal?

Categories : Python

Using pywin32 with iPython
You are correct that package installed to wrong python installation. Also if you install pywin32 make sure you use the correct python when you install windows (unlike mac) allows you to run setup.py directly. This will use the 1st python in your path to determine install location. Standard install: python setup.py install On windows the python is optional, but importantly still implied. type: where python at command prompt to see which python will be used to run setup.py You can also try: /full_path/python setup.py install

Categories : Python

unexpected TypeError with ipython
You are using numpy.core.fromnumeric.sum not the python builtin function (IPython is importing it behind the scenes): In [1]: sum Out[1]: <function numpy.core.fromnumeric.sum> In [2]: sum({1,2,3,4}) Out[2]: set([1, 2, 3, 4]) # returns a set In [3]: del sum In [4]: sum({1,2,3,4}) Out[4]: 10 You can fix this by making sure you are using the "right sum" : import __builtin__ sum = __builtin__.sum

Categories : Python

How to use iPython notebook with ngrok
Author of ngrok here: ipython notebooks and any other websocket connections now work properly as of ngrok 0.22 which is available at https://ngrok.com/download

Categories : Python

IPython Notebook Security
If you run the notebook on your machine, then no, it doesn't send anything externally. There are sites like Wakari where you can use the IPython notebook that's running on a server, and obviously that will send your code and data to their servers. If you did want to expose your notebook server on the internet, then there are security measures that you should take, but that's not necessary if you're just running ipython notebook locally, which is the default way it starts up.

Categories : Security

How to use global variables in IPython
using globals means wrong engineering. If you need a global, that means you need to redesign your code. That's even more true in python. when you do really want to use a global (maybe the only acceptable case: singleton, though in python, you'd only scope the singleton more globally than where you use it...), you need to declare your variable as global, and then attribute it a value. for example: global bar bar = [] def foobar(): bar.append('X') RTFM: http://docs.python.org/release/2.4/ref/global.html Do you use the "global" statement in Python? about the ipython part, my example does work: In [1]: global bar In [2]: bar = [] In [3]: def foo(): ...: bar.append(3) ...: In [4]: foo() In [5]: foo() In [6]: foo() In [7]: bar Out[7]: [3, 3, 3]

Categories : Python

ipython notebook on RHEL 6?
If you have all the prerequisites installed, then ipython can simply be installed using easy_install without needing a package. Details of how to do this are given in the ipython documentation - you should take note of both the general ipython requirements and the notebook specific ones. The major thing which might cause a hassle is pyzmq. This will involve compiling and installing the zeromq C libraries, which obviously require C compilers etc. I think by default the pyzmq installer tries to do this for you, but if it fails then you may have to do this compilation manually. If you don't have root access to your machine, or if you want to test things before mucking around with system libraries, then I suggest using virtualenv to create an isolated python package directory in your own hom

Categories : Python

Ipython change interpreter?
Usually distrib ship with ipython for default system Python ipython3 for Python 3 and so I suppose ipython2 for Python2 when ipython default to Python3. If you want something quick for python2, clone source, cd into it, then. $python2 ipython.py --Usual.options

Categories : Python

IPython to use Python27 in Amazon EC2
The simplest way to install packages for a particular Python is to do either: pip-2.7 install ipython which may not exist, or python27 -m pip install ipython which ensures that Python 2.7 is used, and thus the packages are installed in the right locations to be picked up by 2.7. However, it may be cleanest to just create a virtualenv with Python 2.7: virtualenv -p python27 ~/env/py27 And when you use that, it's easier to be sure which Python you are using, without messing with the system-wide install of things. Many people find virtualenvs the easiest / cleanest way to use the non-default Python on a given system.

Categories : Python

ipython: command not found on OSX
Create .pydistutils.cfg in your $HOME following contents [global] verbose=1 [install] install-scripts=$HOME/bin [easy_install] install-scripts=$HOME/bin Run pip install -U --user --force ipython Have a look at https://github.com/pypa/pip/issues/426

Categories : Osx

IPython split screen
You can do this with tmux (http://tmux.sourceforge.net/) With tmux's default configuration, run tmux, then you can vertical split using ctrl-b %. You can move between left and right side with ctrl-b <arrow>. You can also do much more with it, such as horizontal split (ctrl-b "), start a terminal in a tab (ctrl-b c), attach your existing tmux session from another computer ($ tmux attach)... It can be tweaked to use gnu screen's keyboard shortcuts (with prefix ctrl-a). You can also enable mouse support to switch panes, resize them, swich tab (see http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/).

Categories : Vim

IPython install from GitHub
This is generally the quickest way to install IPython from GitHub: pip install -e git+https://github.com/ipython/ipython#egg=ipython The same goes for pretty much any Python package on GitHub.

Categories : Github

tab complete dictionary keys in ipython
It's not built into IPython. If you want to add it, have a look at this, where someone hacked a solution: https://github.com/ipython/ipython/issues/1533 Also, there are many short and easy ways to create objects from dictionaries, to gain the usual tab completion. If that would help you, use one of the ways described in this question: Convert Python dict to object

Categories : Python

Passing arguments to modules in IPython when using run -m
Add -- to stop the command-line parsing at a certain point: In [1]: %run -m my_packages.my_module -- -verbosity 20 This is standard behavior used by argparse for adding extra positional arguments.

Categories : Python

How to resume iPython 0.13.2 session with logging
All these save/restore sessions work by saving the interactions as py files and then trying to run the py file during restore. If an error like undefined variable happens, that prompts a python error and restore halts there, but it does restore values stored upto the error condition. To avoid storing error conditions, use the suggestion at chosen answer of How to save a Python interactive session? : save my_session_name 1-4 6 9 Where my session will get the commands in In[1] through In[4] and skip In[5], save In[6], skip In[7], In[8] and save In[9]. This way you avoid offending interactions. Restore the session later: %run my_session_name.py

Categories : Python

read-only cells in ipython notebook
There is an extension for IPython that is supposed to that: Read Only Cell extension. Getting it to work is something else, but it is there.

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.