How to define imshow( ) in ipython - ipython

I was given the code itself from the prof. so theoretically it should work, but I am getting an error.
import pyfits as pf
target_i = pf.getdata('file.fits')
header = pf.getheader('file.fits')
imshow(target_i,interpolation='nearest',origin='lower')
When I put in the imshow command it says 'module' object has no attribute 'imshow'. Im assuming this means I need to define imshow? How would I do this? I can ask the professor if need be, but I am quite the procrastinator on this project and I don't think he would appreciate learning that I just started.
Any help would be greatly appreciated.

If you are using ipython, the easiest way to import imshow is just to add this line to the top of your code:
%pylab
or
%pylab inline
This will import imshow from matplotlib directly into your namespace. It's surprising that it thinks imshow is a module... did you import it or define it as a variable somewhere prior?

Related

Documenter.jl UndefVarError

I am trying to create a documentation for a Julia module using Documenter.jl. Now I imported a module which documenter cannot find for some reason. More explicitly: I imported SparseArrays.jl via import SparseArrays and am referencing SparseArrays.AbstractSparseArray in a docstring. (I also have SparseArrays.jl installed.) Yet I get ERROR: LoadError: UndefVarError: SparseArrays not defined. What's the reason and how can I fix this?
EDIT: This is what the relevant parts of the code look like:
module ExampleModule
import SparseArrays
include("example.jl")
end
example.jl:
"""
f
does stuff.
"""
function f(x::SparseArrays.AbstractSparseArray)
return
end
index.md:
```#docs
f(x::SparseArrays.AbstractSparseArray)
```
Most likely you have imported it in a separate code block. See here for an explanation of the issue.
Also you might need to add import SparseArrays in setup code as explained here. This is needed if e.g. you have doctests inside docstrings.
Here is an example how it is done in DataFrames.jl (in general DataFrames.jl has doctests enabled both in docstrings and in documentation code so you can have a look at the whole setup we have there).
If this is not the reason then could you please share your code in the question so that it can be inspected?

Autocomplete in Anaconda

I would kindly ask for in-kind assistance please.
I am using Anaconda 3 (the latest version) on Windows.
It appears that autocomplete works with libraries only e.g. when I type pd (pd is imported pandas library) and put dot I get pip up list of functions.
When I try to do the same for dataframe object (which has been defined earlier as below:
df=pd.read_csv('file.csv')
I get no pop up list.
Any ideas what might be the problem and how to resolve it?
In addition, why help (ctrl+ i) does not work with dataframe objects e.g. when placing cursor in front of df.dropna() I see no help in upper right help window.
Please advise. Thanks

FlashDevelop error while importing Box2D

I'm new to flash development, so I'm watching a tutorial on how to use FlashDevelop. The video recommended I use Box2D and explained how to use it as a global classpath, which I have done.
I was messing around with the code using what the person in the video was showing, just trying to get an output. As I typed, FlashDevelop was adding in the import statements for me.
import Box2D.Collision.Shapes.b2CircleShape;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Dynamics.b2FixtureDef;
import Box2D.Dynamics.b2World;
import Box2D.Dynamics.b2Body;
When I run the program though, it's returning this:
col: 31 Error: Definition Box2D.Collision.Shapes:b2CircleShape could not be found.
It's returning a variation of that for each import.
I've checked and the files are indeed there. I'm really not certain what this could be; it's possible I just missed a step.
Any ideas?
(Sorry if I formatted this question incorrectly, I'm new to this site.)
It's maybe cause you are using an old version
I think these are your choices :
1) you have to do an update
or
2) use "b2CircleDef"
See the code source in this link the change are commented
http://www.emanueleferonato.com/2010/01/27/box2dflash-2-1a-released-what-changed/
Hope that was helpful !
Good luck

ImportError on scipy.misc.imrotate

I'm in the midst of trying to create my own radon transform function, for which I need to rotate the simple image I've created. According to the documentation, the function is in scipy.misc.
However,
from scipy.misc import imrotate
gives me "could not import name imrotate"
and
import scipy.misc
scipy.misc.imrotate(myImage,theta)
says that scipy.misc does not have a module named 'imrotate' when I try to call the function.
I've tried removing the '--pylab inline' arguments from my launch, and I've made sure the PIL/Image libraries aren't imported, because I've heard that there were problems with that in other threads, but nothing seems to make it work.
I've gotten around it for now by using a different suite, the scikit-image library, but I'd prefer to use the scipy version if I can, because it's more commonly used.
scipy.misc.imrotate requires the library PIL and I guess that is your problem. Ether it is not installed at all or not installed correctly.
You can use scipy.ndimage.interpolation.rotate instead.

Have Matlab type a string as if from keyboard

I was wondering if anyone knew if it is possible to have MATLAB type a string for you, as if the user had typed it on the keyboard. I believe it can be done using a shell script or an applescript, but I was wondering if Matlab had a native implementation.
I have tried searching around for it, but have not had any luck. It is not super necessary, but I am just super lazy and want to write a script that will automatically enter information into an application after MATLAB has calculated stuff.
If you know of another simple way of doing this, let me know as well. Thanks a lot!
EDIT:
Adding some code that I used in response to an answer below, using the Java Robot Class
function robotType(text)
import java.awt.Robot;
import java.awt.event.*;
SimKey=Robot;
for i = 1:length(text)
if strcmp(text(i),upper(text(i))) == 0 || all(ismember(text(i),'0123456789')) == 1
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
else
SimKey.keyPress(KeyEvent.VK_SHIFT);
eval(['SimKey.keyPress(KeyEvent.VK_',upper(text(i)),')'])
eval(['SimKey.keyRelease(KeyEvent.VK_',upper(text(i)),')'])
SimKey.keyRelease(KeyEvent.VK_SHIFT);
end
end
end
Warning, code may not be the best, but hey it was written in like 5 minutes.
I ended up writing an applescript to do everything that I needed Matlab to do. Unfortunately this will not help the Windows people, but myself and the other people using the script are mac users, so it works for us.
I have however, edited my question above to include code that I used initially in Matlab to auto type things. Simply run command as robotType('SomeString') and it will type that string.
I do not believe it will hand spaces or random characters that well, or at all, but it is good enough for abc123. Sorry for no final solution on this.