ipython-notebook

image palette's dimension reduction using matplotlib and/or numpy to create blocky image

给你一囗甜甜゛ 提交于 2019-12-10 00:21:57
问题 I am using iPython notebook, I have a 512x512 image that I want to 'transform' into a 'blocky' image using 'nearest' interpolation of colors in the blocks, similar to the 'mosaic' filter in Photoshop, for some further manipulation of a batch of pictures. In Photoshop, you load the image and you can set the filter to 'Mosaic', and set the 'block size' in pixels. Here there is a partial explanation about how to do it using numpy, but since I am not a numpy expert, I found a 'shortcut' that is

How to keep the current figure when using ipython notebook with %matplotlib inline?

人走茶凉 提交于 2019-12-09 19:17:47
问题 I could not find answer for this, so please let me ask here. I would like to keep the current figure in ipython notebook when using %matplotlib inline . Is that possible? For example, I want to plot 2 lines in a graph plt.plot([1,2,3,6],[4,2,3,4]) plt.plot([3.3, 4.4, 4.5, 6.5], [3., 5., 6., 7.]) If I put those two command lines in a cell it is ok. The graph shows two lines. However, if I put them separately into two cells, when the second cell (plt.plot([3.3, 4.4, 4.5, 6.5], [3., 5., 6., 7.])

IPython notebook interactive function: how to set the slider range

断了今生、忘了曾经 提交于 2019-12-09 17:25:35
问题 I wrote the code below in Ipython notebook to generate a sigmoid function controlled by parameters a which defines the position of the sigmoid center, and b which defines its width: %matplotlib inline import numpy as np import matplotlib.pyplot as plt def sigmoid(x,a,b): #sigmoid function with parameters a = center; b = width s= 1/(1+np.exp(-(x-a)/b)) return 100.0*(s-min(s))/(max(s)-min(s)) # normalize sigmoid to 0-100 x = np.linspace(0,10,256) sigm = sigmoid(x, a=5, b=1) fig = plt.figure

How to have a function return a figure in python (using matplotlib)?

允我心安 提交于 2019-12-09 17:12:14
问题 Assume that I have some data, and I want to create a plot of this data by passing it to a custom plotting function (myplot()). I am using the matplotlib's modules in myplot(). I would like myplot() to return the handle to a figure, and not plot display the plot when I call this function. Here is a sample code and output from iPython. I have two questions regarding this: Why do I still see a plot, even though I am assigning the output of myplot() to f? What do I need to supress this plot when

ipython notebook - $DISPLAY variable error [duplicate]

瘦欲@ 提交于 2019-12-09 16:17:47
问题 This question already has an answer here : ipython notebook on linux VM running matplotlib interactive with nbagg (1 answer) Closed 3 years ago . I am running IPython notebook on an ubuntu vm. Everything works great so far, except I'm unable to do interactive matplotlib plots. The error I get is: TclError: no display name and no $DISPLAY environment variable And I'm just trying to follow these super basic tutorials. http://nbviewer.ipython.org/github/jakevdp/matplotlib_pydata2013/tree/master

Jupyter Notebook time profiling

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 15:25:24
问题 So I installed jupyter notebook through anaconda and I am working on python 3 kernel. I am trying to do Time profiling using %time magic command as show here The problem is that it only prints the Wall Time not the CPU Time using %time or %%time does not help %time prints the wall time for the first line only %%time prints the wall time for the whole cell I am not sure if there any specif config to print the CPU time EDIT To clarify using %%time should print two metrics for the whole cell

IPython notebook: How to connect to existing kernel?

◇◆丶佛笑我妖孽 提交于 2019-12-09 15:17:51
问题 I am able to connect two ipython console session to one kernel by: $ ipython console In [1]: %connect_info { ... Content of JSON with info for connecting ... } Paste the above JSON into a file, and connect with: $> ipython <app> --existing <file> or, if you are local, you can connect with just: $> ipython <app> --existing kernel-43204.json or even just: $> ipython <app> --existing if this is the most recent IPython session you have started. And accordingly I can substitute the <app> by

remove nbconvert --to html 'in' and 'out' prompts based on cell metadata

ぐ巨炮叔叔 提交于 2019-12-09 13:42:15
问题 I'd like to remove the red and blue 'In' and 'Out' prompts when running nbconvert --to html , based on cell metadata. With cell metadata such as: {'cell_tags': {'cutcode_html': true}} The following sucessfully removes the 'In' prompt: {% block input_group %} {% if cell['metadata'].get('cell_tags',{}).get('cutcode_html','') == True -%} <div></div> {% else %} {{ super() }} {% endif %} {% endblock input_group %} I'd like to do the equivalent thing for the output prompt. There has been discussion

How do I configure mathjax for iPython notebooks?

馋奶兔 提交于 2019-12-09 04:50:31
问题 I'm trying to find a way for mathjax to not use STIX fonts for math in my iPython notebook. Instead, I'd much rather have it use the 'TeX' fonts. According to the documentation for Mathjax I should use: MathJax.Hub.Config({ "HTML-CSS": { preferredFont: "TeX" } }); That being said, I'm not sure where to put this. I've already tried putting this chunk of code into my custom.js file pertaining to my own ipython profile, but it doesn't work. Ideally, I'd like to make ipython profile specific

Pipe Ipython magic output to a variable?

痴心易碎 提交于 2019-12-09 02:10:28
问题 I want to run a bash script in my ipython Notebook and save the output as a string in a python variable for further manipulation. Basically I want to pipe the output of the bash magic to a variable, For example the output of something like this: %%bash some_command [options] foo bar 回答1: What about using this: myvar = !some_command --option1 --option2 foo bar instead of the %%bash magic? Using the ! symbol runs the following command as a shell command, and the results are all stored in myvar