in IPython if I use the following code, I can see the plot inline:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,5,6])
but if I use this code, the graph does not appear inline or in separate window:
%matplotlib inline
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3],[4,5,6])
I am running Python 3.5.2 |Anaconda 4.1.1 (64-bit)| on Windows 7
matplotlib version is 1.5.1
Related
import plotly.express as px
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
I imported these libraries and used %matplotlib inline . The code runs fine but the terminal in vs code shows the error :
Syntax Error: invalid syntax
I found an answer to use %matplotlibinline in VS Code
# Suppress matplotlib user warnings
# Necessary for newer version of matplotlib
import warnings
warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib")
#
# Display inline matplotlib plots with IPython
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
%matplotlib inline is not a valid python command. This has a specific meaning when used in ipython/jupyter.
I was running seaborn ver. 0.10.1 on my jupyter notebook. This morning I upgraded to the latest version 0.11.0. Now, my kde jointplot doesn't give the color mapping that it used to. The code is the same. Only the versions are different.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib notebook
np.random.seed(1234)
v1 = pd.Series(np.random.normal(0,10,1000), name='v1')
v2 = pd.Series(np.random.normal(60,15,1000), name='v2')
v3 = pd.Series(2*v1 + v2, name='v3')
# set the seaborn style for all the following plots
sns.set_style('white')
sns.jointplot(v1, v3, kind='kde', space=0);
The function kdeplot (which is used internally by jointplot()to draw the bivariate density plot) has been extensively changed in v.0.11. See What's new and the documentation.
You now have to pass fill=True to get a filled KDE, and you need to specify thresh=0 if you want to fill the available space with color.
sns.jointplot(x=v1, y=v3, kind='kde', space=0, fill=True, thresh=0, cmap='Blues');
I am using Jupiter notebook with jupyter themes (one dork). However, I still want my figure to have a white face color and not adapt to the theme.
This can be accomplished using...
%matplotlib inline
import matplotlib.pyplot as plt
fig, ax = plt.subplots(facecolor='w')
ax.plot(np.arange(40), np.arange(40))
HOWEVER, when using %matplotlib notebook, this does not work ...
%matplotlib notebook
import matplotlib.pyplot as plt
fig, ax = plt.subplots(facecolor='w')
ax.plot(np.arange(40), np.arange(40))
Any thought on this behavior??
The following code example uses the RectangleSelector widget, so that we should see a continuously updated rectangular patch over the plot. However, nothing can be seen, unless we set useblit=False. What's wrong?
This is with matplotlib 2.2.2 and wxpython 4.0.1 on linux. The tkagg backend works fine.
#!/usr/bin/env python3
import matplotlib
from matplotlib.widgets import RectangleSelector
if __name__ == '__main__':
matplotlib.use('wxagg')
import matplotlib.pyplot as plt
figure = plt.figure()
rect = RectangleSelector(figure.gca(), (lambda e1, e2: print(e1, e2)), useblit=True)
plt.show()
I am assuming you are using Linux. Check following link:
https://github.com/matplotlib/matplotlib/issues/11425
Wayland seems to have a bug when blitting.
I need to open a bar charts in Matplotlib in a browser-Like Firefox- but I shouldn't use Bokeh in my Project. Any suggestions?
Use the WebAgg backend, which opens a browser window with the plot and is fully interactive like the Qt or GTK window.
import matplotlib as mpl
mpl.use('WebAgg')
import matplotlib.pyplot as plt
# do your plotting
plt.show()
For example:
>>> import numpy as np
>>> a=np.random.random(100)
>>> b=np.random.random(100)
>>> plt.plot(a,b)
Opens http://127.0.0.1:8988/ showing:
IPython with %matplotlib inline as demonstrated here