Seaborn Plot doesn't show up - python

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.

Related

How to center bar plot in python matplotlib?

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()

Update plotly chart in jupyter notebook

I'm creating a plotly chart in jupyter notebook. Because I'm testing some algorithm I want to add data after the initial fig2.show(). But when I update the data and call fig2.show again a new chart is being rendered. How can I update the chart instead of creating a new chart?
This should be an easy task - but it's way to hard to find for me in the documentation.
import plotly.offline as pyo
import plotly.graph_objs as go
import numpy as np
# Set notebook mode to work in offline
pyo.init_notebook_mode()
fig2 = go.Figure(data=go.Scatter(x=moreX2, y=moreY2))
fig2.show()
Then I'm using update:
moreX2.append(2)
moreY2.append(5)
fig2.data[0].update({"x": moreX2, "y": moreY2})
The chart isn't being rerendered and I tried to call fig.show() again, which just creates a new chart.
This answer worked for me, and seems like the ideal answer to this question as well. I've voted to mark this as a duplicate.
To summarize: by wrapping the Figure in a FigureWidget, we can now do exactly what the OP wanted. Although on Colab I did have to give some extra permission by calling the following:
from google.colab import output
output.enable_custom_widget_manager()

Inline Interactive Plots with Julia in jupyter notebook

when I use
%matplotlib notebook
import matplotlib.pyplot as plt
I get interactive plots, i.e. I can also zoom into the figure.
For julia this command does not seem to exist. Any ideas?
You can get interactive plots by using Plotly, either directly with Plotly.jl or through its Plots backend.
Today I am thinking about how to enlarge the plot window interactively without referring to python or plotly or something else in Jupiter notebook. And I find a good solution. It is to use the package Interact. A simple example is as follows. You can get an interactive plot in 3 lines.
import Pkg; Pkg.add("Interact")
using LinearAlgebra, Plots, Interact
#manipulate for n in 10:100, w in 200:1000, h in 200:1000
plot(randn(n),randn(n),seriestype=:scatter,label="n=$(n)",size = (w, h))
end
The result looks like this

matplotlib not displaying image on Jupyter Notebook

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

My graph is not showing up and my iPython Notebooks never stops working

When I run the code below my iPython Notebooks starts working on it (I see black dot in the top right corner), but it never stops. I cannot stop it either by pressing button with the black square.
I opened my other notebook and it shows the histogram without any problem.
What can be the reason?
Thank you.
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers = normal(size=1000)
plt.hist(gaussian_numbers)
plt.title("Gaussian Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
UPDATE: Created a new notebook. Passed all the code from the previous notebook (including code that gets the data from the internet). Can any other code affect working and displaying the histogram?
There is not other code working when I run histogram.
yo need to use%matplotlib inline
%matplotlib inline
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers = normal(size=1000)
plt.hist(gaussian_numbers)
plt.title("Gaussian Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
see this other thread to automatically do this on the IPython configuration Automatically run %matplotlib inline in iPython Notebook

Categories