I figured this should be simple but I guess not.
from scipy import misc
import matplotlib.pyplot as plt
img = misc.imread("Alyson.jpg")
plt.imshow(img)
plt.show()
It draws a blank canvas. Inspecting the array the values were obviously loaded correctly. I don't really know what the issue could be. I've also tried loading it with matplotlib.image.imread and with PIL.Image.open to the same effect.
I'm running Lubuntu 13.04. Here are some versions of various libraries:
Pillow==2.5.2
matplotlib==1.3.1
numpy==1.8.2
scipy==0.14.0
EDIT: SOLVED!
I switched the rendering backend using matplotlib.use("WX").
Not certain what the cause of the problem was, but I switched the backend to wxPython and images loaded with misc.imread or matplotlib.image.imread worked fine.
import matplotlib
matplotlib.use("WX")
import matplotlib.pyplot as plt
...etc
Related
i'm getting started with scikit-geometry and am trying to reproduce some of the examples, but the plot function doesn't work as expected.
i'm working in VSCode and managing my environment with Anaconda on Windows 10.
i'm just reading through the samples in the notebook. the snippet runs, but no graphic is displayed.
import skgeom
from skgeom.draw import draw
from matplotlib import pyplot as plt
import math
a = skgeom.Point2(4, 5)
print('a:', a)
draw(a, color='purple')
the docs indicate that the draw function is built from the matplotlib plot function, but it doesn't support the .show() method, so i'm not really sure what i'm doing wrong.
suggestions?
I am working on a Coursera cert and I noticed that the plots in their example labs and assignments come out like this:
I would like to do a couple things. One, if possible(but might not be necessary), to remove the legend "figure 1", the on/off symbol and the buttons at the bottom of the image. By the way, I really don't understand where this feature comes from, I hope someone can explain. Two, the main thing I want to fix is making all the labels(ticks) in the y-axis visible, i.e. move them towards the right.
The Python version in their Jupyter notebook is:
from platform import python_version
print(python_version())
3.6.2
The imports I am working with:
%matplotlib notebook
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings('ignore')
And the code that generated the plot:
categ_series.plot(kind='barh', figsize=(8, 6))
plt.show()
I am using ubuntu 14.04 and coding in jupyter notebook using anaconda2.7 and everything else is up to date . Today I was coding, every thing worked fine. I closed the notebook and when I reopened it, every thing worked fine except that the image was not being displayed.
%matplotlib inline
import numpy as np
import skimage
from skimage import data
from matplotlib import pyplot as plt
%pylab inline
img = data.camera()
plt.imshow(img,cmap='gray')
this is the code i am using, a really simple one but doesn't display the image
<matplotlib.image.AxesImage at 0xaf7017ac>
this is displayed in the output area
please help
You need to tell matplotlib to actually show the image. Add this at the end of your segment:
plt.show()
To show image in Jupyter Notebook by matplotlib, one should use the %matplotlib inline magic command and plt.show().
As for your code, adding plt.show() after plt.imshow() expression will make the image shown.
If using the inline backend, you just need to call plt.show().
If you are using the notebook backend (%matplotlib notebook), then you should call plt.figure() before plt.imshow(img). This is especially important if you wish to use interactive figures!
change kernel from xpython to original python kernel
I am creating a bar chart with seaborn, and it's not generating any sort of error, but nothing happens either.
This is the code I have:
import pandas
import numpy
import matplotlib.pyplot as plt
import seaborn
data = pandas.read_csv('fy15crime.csv', low_memory = False)
seaborn.countplot(x="primary_type", data=data)
plt.xlabel('crime')
plt.ylabel('amount')
seaborn.plt.show()
I added "seaborn.plt.show() in an effort to have it show up, but it isn't working still.
You should place this line somewhere in the top cell in Jupyter to enable inline plotting:
%matplotlib inline
It's simply plt.show() you were close. No need for seaborn
I was using PyCharm using a standard Python file and I had the best luck with the following:
Move code to a Jupyter notebook (which can you do inside of PyCharm by right clicking on the project and choosing new - Jupyter Notebook)
If running a chart that takes a lot of processing time it might not have been obvious before, but in Jupyter mode you can easily see when the cell has finished processing.
import numpy as np
import matplotlib.pyplot as plt
from scipy import misc
img = misc.imread('W0002_0001.png')
plt.figure()
plt.imshow(img)
plt.show()
I want to read the first image that can be found here. The problem is that the image displayed is not the one I should see. I get:
When I should be getting:
When looking in detail, I noticed that the real image could be seen in the first row of the obtained image, repeated several times.
Also, I had several segfaults when trying to import the image several times in a row with IPython, although it seems like I cannot always reproduce the issue.
I tried reading the image with Pillow and it worked fine.
Do you have any idea what might cause that?