Currently in IPython, when you call %pylab inline or %matplotlib inline the following message displays under the code block.
"Populating the interactive namespace from numpy and matplotlib"
How I can suppress this message from being displayed?
I don't think there's a builtin way of suppressing that message since if you look at the %pylab magic function in this file you can see that the print statement is hard coded in there.
If this is a one-off kind of thing you can simply comment/remove that print line from your local library. (Typically it would be found at /usr/local/lib/python2.7/dist-packages/IPython/core/magics/pylab.py.) Or possibly redirect stdout to devnull or something like that.
Related
I have python embedded into my program and added a few functions using the Python C API. I'd like to get PyLance IntelliSense providing autocompletion for it.
After setting up paths to a dummy python file (with dummy functions), PyLance seems to suggest auto completions for my functions but also adds the top-level from x import y statements. I've tried to set the python.analysis.autoImportCompletions to false but it disables the autocompletion entirely.
So, how to get the autocompletion without PyLance adding the import statements at the top? (I know it's not practical but I think it suits my use case here)
I got a super graph that I would like to export as an html file to be showed on an website but I don't know how to figure that. Have you got an idea ?
You can use mpld3. This is a great tutorial. The mpld3 library's main functionality is to take an existing matplotlib visualization and transform it into some HTML code that you can embed on your website.
Use fig_to_html file, which accepts a matplotlib figure object as its sole argument and returns HTML.
To use the fig_to_html method , simply add the following code to the end of our Python script:
html_str = mpld3.fig_to_html(fig)
Html_file= open("index.html","w")
Html_file.write(html_str)
Html_file.close()
Here is the code I write in pydev combined with eclipse.
import matplotlib.pyplot as plt
fig=plt.figure()
as I know, 'fig' is a instance of 'matplotlib.Figure' class,when I write :
fig.
it seems pydev can't provide method calltip for fig. I cannot figure out what's going on, since for other module , like numpy, it works well.by the way, if i use a matlab-like interface, for example,
plt.plot()
pydev does provide the calltip for function arguments.
is there a way to solve this problem? I will appreciate it if anyone give a solution .
Forgive my poor english:-D
fig is an instance of matplotlib.figure.Figure so what you can do is importing import matplotlib.figure and creating an instance of that. Then, writing fig to the editor, you should get the tooltip you want.
The following is a screenshot from Spyder, so I haven't actually tested it in pydev.
I am not aware of any other possibility. The reason is that for the requested functionality to work the editor would need to load all kinds of modules, which are not actually imported in the script.
The issue is that some cases are too dynamic for PyDev to know about the actual type of the object that some method returns (which appears to be the case).
If you know the type, you can manually type it locally.
i.e.: Add the comment:
#: :type fig: matplotlib.figure.Figure
right before the fig assignment.
See: http://www.pydev.org/manual_adv_type_hints.html for more details.
I want to do something like the following using a loop and PyPlot to plot in figure windows. My question is how to save the figure windows to a movie file within the loop?
using PyPlot
for k=1:5
pcolormesh(rand(10,10))
if k==1; colorbar(); end
# save figure window to movie file here??
sleep(.5)
end
This is possible by directly using the animation submodule of matplotlib (the underlying Python library that PyPlot.jl wraps). However, it is painful; see e.g. the following notebook (in Spanish):
https://github.com/dpsanders/fisica_computacional/blob/master/como_animar.ipynb
The simplest way, however, seems to be using Plots.jl:
https://github.com/tbreloff/ExamplePlots.jl/blob/master/docs/pyplot_examples.md#functions-adding-data-and-animations.
I'd like the background of my matplotlib plots to be transparent in my IPython notebook. This may sound silly because the notebook itself defaults to a white background but:
1) I use a solarized background and
2) more importantly, I want them to be transparent for when I embed the notebook directly into my blog via nbconvert.
It's easy enough to use something like savefig('file', transparent=True) , but I'm not saving the figures, I am displaying them inline (by calling IPython with ipython notebook --matplotlib inline.
I've been playing around with the IPython notebook configuration file, especially with c.InlineBackend.rc. For example, I upgraded to the dev version of matplotlib to get access to its new savefig.transparent rcParam, and tried configuring that with c.InlineBackend.rc = {'savefig.transparent': True}, but as expected it only affects plots saved with savefig.
Note that I am using the recent IPython 2.0 release. This must be possible somehow, right? Any light that you can shed would be appreciated.
Just to follow up, the issue opened on Github by tillsten has been patched so something like this:
rcParams['figure.facecolor'] = (0,0,0,0)
should work now after you update IPython. Three cheers for open source.
The inline plots are html objects (<img>) with class ui-resizable. So you can change their default behavior by customizing the CSS for your notebooks:
locate your settings for notebooks: in a terminal, type
ipython locate
in the indicated directory, go to subdir profile_default\static\custom (or any profile you want to use instead)
edit or create a CSS file named custom.css
put this in it:
img.ui-resizable
{
opacity:0.4;
}
Close your notebooks, kill IPython and restart it (so that it recreates the served files).
It should work with exported notebooks, as long as you export them as html and you change the css there too.
It's not exactly what you want, but it does the job.