As I learned here, there is an extension for the IPython notebook, that lets you specify the number of lines that are plotted before enabling scroll bars on the output cell. This does not work for Pandas data frames, because the div inside the .output_subarea has the style
max-height:1000px;max-width:1500px;overflow:auto;
even if I set the AutoScrollLimit to no-scroll. How to plot the data frames always without scroll bars?
This was changed for 0.16.2, see here
For ipython >= 3.0.0 will now use the notebook display controls
Related
Does anyone know how to make Pandas outputs display properly in VS Code Jupyter Notebooks?
As you can see in the image, the values for individual columns in the output of a Pandas DataFrame aren't aligned (whereas they are aligned if you use Jupyter Notebooks directly on a web browser).
Click on the 3 dotted lines highlighted in the image above. From there its going to prompt you to select text or html. Click HTML, and the full data frame should show up
For the alignment of pandas, I think I have a relatively simple strategy. We can use IPython module.Use the following code to output the results.
from IPython.display import display
display(df2)
I think you've got a bracket mismatch. Change your code to this:
df2.loc[df2['Airport'] == 'ATL', ['Delay']]
This is a really basic question but I haven't been able to find an answer:
In Jupyter, if I execute two pandas df.describe() calls in the same cell, only the last one's output is displayed. The same is true for .info(), .head() etc. etc.
How do I persuade Jupyter and pandas to display all N of the above outputs sequentially as intended, with the same tabular formatting that is the default for a single output?
FWIW example code would be:
df1.describe()
#...
df2.describe()
dfN.describe() # Only the result of the final call is displayed
Points from comments addressed:
print(df1.describe()) works, but does not render the table identically to how it is rendered by describe() itself.
Displaying two pandas tables side-by-side (Jupyter notebook display two pandas tables side by side) may work, but doesn't scale to N tables.
You can configure your current session and specify what values to show by InteractiveShell.ast_node_interactivity:
%config InteractiveShell.ast_node_interactivity = 'all'
I'm using PyCharm with Darcula theme and Jupyter notebook from anaconda package.
I faced a problem that Darcula theme is inconvinient to use with Jupyter notebook
For example, pandas plot's axis is not readable.
I tried to find out, how to change notebook cell background, but looks like that there is no possibility to do that.
Of course, I can change PyCharm theme to another, but I used to work under this theme.
And of course, I can change background of plot in code, but it is inconvinient to change background for each plots (for example, if I work with ready notebook)
Can I change cells background or the only way is to change theme to another?
Probably a bit too late, but here is a solution for future reference:
1 - Go to PyCharm > Preferences and type in the search bar "Invert image outputs for dark themes"
2 - Go to Language & Frameworks > Jupyter and uncheck the "Invert image outputs for dark themes" box.
3 - Restart PyCharm for option to take effect.
Per https://stackoverflow.com/a/40371037/2529760, you can use
fig = plt.figure()
fig.patch.set_facecolor('white')
or
plt.gca().patch.set_facecolor('white')
to force a white background beneath the axis labels on a per-plot basis. You can use
plt.rcParams['figure.facecolor'] = 'white'
to achieve this on a per-notebook basis.
To change this setting globally, normally you can edit the matplotlibrc file, but it appears Jupyter overrides this to some degree. Following https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-inline-defaults.ipynb, you can create a file ipython_kernel_config.py at the correct location (~/.ipython/profile_default by default) containing the line
c.InlineBackend.rc = {'figure.facecolor': 'white'}
Any of these options will ensure the plot has a white background so the text is legible.
You can try the seaborn package:
import seaborn as sns
sns.set_context('notebook')
sns.set_style('white')
It will change the output plot background to white.
The temporary workaround for me is to explicitly call plt.show() at the end of cell.
I am also looking for a better solution.
I have a long Jupyter notebook code and there is many cells, which are redrawing the actual graph plot. When I am running cells after changing their contents I need to check the plot, but I always need to scroll up and down. I would prefer to watch the plot changes in separated window (I am using two monitors), so I will change the cell content, run the cell, and then just turn my head and see the plot - without any scrolling. Is there a way how to do that? I know it can be done by Spyder, but I want to do it in Jupyter notebook, since I use a lot of notebook advantages, such as Latex notes and headings between cells. Thanks a lot for any advice!
It would be great if you could tell us how you print your graph (what library ?). Ipython provide magic command. For example, if you use matplotlib to plot some figures, just add %matplotlib qt on top of your cell to make the plots appear in a separate window.
See the list of magic command available here.
I am using seaborn which is a library based on matplotlib and that enhances some styling features of matplotlib.
If I write the following script in the editor and run it, I get the graph correctly displayed in the image file.
import seaborn as sns
sns.plt.plot([2,4,8,16],[1,2,3,4])
sns.plot.gcf()
sns.plot.savefig("C:\\in\\Fig1.png")
The problem is that when I write those same lines the interactive way in iPython one by one, I get a blank image file. However, the image is correctly displayed in iPython as soon as I execute the second line:
sns.plt.plot([2,4,8,16],[1,2,3,4])
So, the question is: why is this happening in the first place, and how do I get an image file with the graph inside it by using iPython?