Resolution and Display issues with Matplotlib in Jupyter Notebook - matplotlib

I am running matplotlib on my MacBookPro and my second monitor is a Dell S2721HS. The images in my Jupyter Notebook and the html file are fuzzy and pixelated. While this same code is run by my boss on her pc and everything is clear.
We are running this line of code at the start of our notebook.
from IPython.display import display, HTML
display(HTML('\<style\>.container{ width:80% !important; align-items: left; float: left; text-align:justify}\</style\>'))
And we are running this line of code to export
!jupyter nbconvert --to=html*toc --no-input "file*name_here.ipynb"
Is this an issue with my resolution & display, or is this an issue with my anaconda or environment?
I have tried mirror, extended, using my mac with Built-in Retina as the main display, and dragging my stuff over to my Dell Monitor, expecting clear images, but no luck.
I have also tried both of these options; while the SVG did work, it made my images very large, which I could mess with the figsize possibly. Option 2 was still blurry.
Thank you!

Related

Jupyterlab kernel remains busy with matplotlib widget

I'm new to Jupyterlab and matplotlib so this may be a dumb question but here goes.
FYI: I'm using the standalone jupyterlab app on a mac.
When I make a simple interactive plot using the matplotlib widget magic, the kernel stays busy forever. I had found an earlier post on stack overflow about putting the magic in the 2nd cell (why this works?) and the plot works fine, I just want to know what's going on with the kernel.
The code, which works fine, is just:
import numpy as np
%matplotlib widget
import matplotlib.pyplot as plt
x = np.arange(10)
y = 2*x
plt.figure()
plt.scatter(x,y)
A screenshot to illustrate.
Kernel stuck running in top right of shot
UPDATE: To be clear, this is occurring on the Jupyterlab Standalone app. If I run this on jupyterlab launched via the anaconda navigator, it works fine. For whatever reason, it seems confined to the standalone app only.
As for the App, I installed it via the binary at GitHub. I'm running 3.3.2-2

Matplotlib figure looks different when saved, compared to rendered in jupyter notebook

I am using seaborn style darkgrid. When I render the figure in jupyter it looks great. But when I save it with savefig(figure.jpeg, dpi=300). The colors of the grid are bad. Funny, when I upload the figure here, it looks good again. What is going on? And when I drop it in Chrome it looks bad. Is this a transparency issue? It is mainly the darker area in the background that is affected.
%pylab inline
import seaborn as sns
sns.set_style('darkgrid')
plot(something)
I would like to save the figure as it is displayed in the jupyter notebook so I can use it in other applications. What does the browser, what other image viewers don't have?
I tried formats jpeg and png. And saved the figure with transparency=True and transparency=False.

python-pptx with matplotlib fix image resolution

i am trying to generate a graph using matplotlib and save it to python-pptx . everything is working fine but the image resolution is low when imported to pptx.( i am just saving to memory using StringIO then using add_picture() in pptx to add image)
when i do :
some_image_in_memory = StringIO()
plt.savefig(some_image_in_memory)
it works fine but give low res image but when i do :
plt.savefig(some_image_in_memory, format='svg')
i get error:
cannot identify image file <StringIO.StringIO INstamce at ..>
is this even correct? svg should maintain resolution but i cant read this in pptx.
I got around this by setting dpi value to savefig():
ex
plt.savefig(some_image_stream_in_memory, dpi=1200)
Unfortunately, PowerPoint does not directly support the SVG format (I've heard it's a turf issue between MS and Adobe). I expect that explains the error you're getting when you save with format=svg.
Other folks seem to have good luck with the PNG format from matplotlib. I kind of suppose that's the default image format, but might be worth a check.
The other thing that occurs to me is I don't see anywhere you have specified the size of the graph to be saved from matplotlib. If it is getting saved as a small image and then getting scaled significantly larger when displaying it in PowerPoint, this will produce a "grainy" appearance.

Viewing graphs in Jupyter or IPython

I am trying to use both bokeh and matplotlib in my IPython notebook... Neither work perfectly.
Attached is a screen shot of Bokeh. Matplotlib explanation is below.
Here are my system specs:
-Windows 7 with Vagrant
-Jupyter/IPython
BOKEH -- buttons are static images; there is no resizing, yet the graph is interactive
Should look like from this website: http://docs.bokeh.org/en/latest/docs/quickstart.html
MATPLOTLIB -- only static shots appear when it should be zoomable, etc (like bokeh)
1) read the documentation.
you would only change output_file() to a call to output_notebook() instead.
Which you did not seem to do above.
2) Why should it ? What di you do to make it zoomable ?
3) try not to post 2 unrelated question at the same time.
You appear to be using an older version of Bokeh. The issue with the CSS problems (button appearance) has been fixed for some time. As mentioned above, you will need to execute output_notebook() to load Bokeh for IPython notebook usage. For future reference, questions like this greatly benefit from providing as much information as possible (e.g., Bokeh and browser versions, platform information, etc.) Without that information it is impossible to diagnose problems with any certainty.

Setting Device Width for Remote Webdriver in Selenium

I am using Selenium grid 40 with Firefox remote driver that runs in windows 7. I also use C# API. I was wondering how to Set Device width on headless Firefox browser. The device width is less than ipads max width and this causes it to pick up ipad specific css that is defined like below:
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* For landscape layouts only */
}
I have already changed window size using:
driver.Manage().Window.Size = new System.Drawing.Size(1290,900)
But it still picks up those css directives.
Other information: My grid node is virtual machine that nobody actually logs into. I remotely run the selenium grid, and that might be the reason why device width is small. it might default to smallest resolution for windows. If there is way to change that it might help me, but I am not aware of it.
Update: I tried to set all instances of DefaultSettings.XResolution, DefaultSettings.YResolution and DefaultSettings.BitsPerPel in registry to 1290, 900 and 16 through a powershell script and restart the computer but it didn't work.
I don't know how to set the device width using selenium, but I figured out how to set it using the remote frame buffer. For me this was Xvbf. I pass in the screen resolution when I start the service.
Below is an example of an Xvfb service with a resolution of 1024x768 with a depth of 24.
https://gist.github.com/dloman/931d65cbb79b00593ac3dd5d0cdf37d9
My experience is limited to using the Python implementation of Selenium so this may not work for you, but there you can use driver.set_window_size(width, height) before performing the driver.get() action that will load the desired page.
The key is the order in which you perform these actions: you want to tell selenium to change the dimensions of the browser before you load the page, because otherwise you are simulating the same behaviour as resizing a browser window after the initial page load. As you may know, when resizing a browser window, a page reload is needed for some 'responsive' features to be activated.