Customized matplotlib style with matplotlibrc doesn't load - python-3.x

I customized my own matplotlib style with matplotibrc by using the commands:
plt.style.reload_library()
plt.style.available
I was able to retreive my cumstomized style. However, when trying to load it with the command:
import matplotlib
#matplotlib.use('TkAgg')
matplotlib.rcParams["backend"] = "TkAgg"
import matplotlib.pyplot as plt
plt.style.use('MyCustomedStyle')
It's not being loaded. As you see, I have also tried to change the backend to use TkAgg for an interactive session, since I want to have it printed out on the screen.
I'm not getting any error messages. Still, however, it is not changing to my customized style.
I have also tried the command:
plt.rcParams.update(plt.rcParamsDefault)
%matplotlib inline
What am I doing wrong?

Related

matplotlib.plot doesn't show any image or plot without any error

I'm trying to show some images on VScode in Ubuntu, but matplotlib doesn't work. For example, even the most simple code such as:
import matplotlib.pyplot as plt
s_in = plt.imread("/media/aro/New Volume/Super resolution dataset/set5/Test/BSDS100/3096.png")
plt.imshow(s_in)
plt.show()
is not working, and it doesn't show any errors or warnings. What should I do?
In case anybody has got the same problem as mine. The error was because of the backend. So I had to change it. the only backend that worked for me was WebAgg.
Just add the following code at the beginning of your code.
import matplotlib.pyplot as plt
plt.switch_backend('WebAgg')

Why will Seaborn function 'regplot' not run in Jupyter?

I am having trouble with code Seaborn regplot function in Jupyter notebooks using Watson-Studio.
Using Python 3.6, the code appears to get stuck whilst processing, and this happens until I stop the code.
When I run this using IDLE on my Mac, the code runs perfectly and the plot shows.
Seems to happen with plots lmplot and regplot, however boxplots etc do show as normal.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df = pd.read_csv(csv.csv)
sns.regplot(x = 'independent', y = 'dependent', data = df)
The expected results should be a graph of the linear relationship between the two variables, however I am just getting a loading bar.
When I stop running the kernel, the graph exists as a scatterplot with no line of best fit. Of course this has the error in notebook as 'Keyboard Interrupted'.
Could this possibly be a bug? Thanks for your help.
Set ci parameter to none and it will solve your problem.
sns.regplot(x = 'independent', y = 'dependent', data = df, ci = None)

plt.show() not working in pycharm

I am using pycharm after upgrading my python to python 3.5.
I re-run a standard code that i had in place and had a problem with plt.show()
example:
import matplotlib
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
The suggestion by DavidG made things worked fine. But this time when I do
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
i get an error saying
/apps/qtrinst/install/python/anaconda/envs/sx_anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:1401: UserWarning: This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
It didnt get this error before-not sure what happened there.
I think the problem is with your "backend". The documentation has a section entitled "What is a backend?" which will be helpful.
I'm not familiar with WebAgg but I don't think you want to be using it. A more conventional one might be TkAgg which requires Tkinger or Qt4Agg which requires PyQt4. You can switch backends using
import matplotlib
matplotlib.use("TkAgg") # Do this before importing pyplot!
import matplotlib.pyplot as plt
Try using a different Backend. It worked for me when I used QtAgg
PyQt
you will need to install some version of PyQt. At the moment:
pip install PyQt6
Specify the GUI backend
import matplotlib
matplotlib.use("QtAgg")
Try plt.show()
from matplotlib import pyplot as plt
# some code here
plt.show()
This worked flawlessly for me. Hope It worked for you too.

Plotly graph shows a blank space on GitHub

I am using Plotly to make graphs in my IPython notebook. I am able to view graphs on my IPython notebook when I upload them on GitHub they are displayed as blank spaces.
I read on the web that Plotly currently does not support iframes and hence the issue, but is there a workaround?
Here's the link to my GitHub Ipython notebook:
https://github.com/dhavalbhinde/bhinde_dhaval_spring2017/blob/master/Finals/Analysis%203.ipynb
Please, can someone advice how should I handle them?
I found a way to show Plotly plots on Github. They aren’t interactive anymore but it’s better than nothing.
First
import plotly.io as pio
pio.renderers
you can see the list of available renders.
*if you get an error on this step you can simply just install orca:
conda install -c plotly plotly-orca
and then there are 2 possible ways.
you can pass "svg" to .show() like this:
fig = px.scatter_3d(iris, x=transformed_iris['component1'], y=transformed_iris['component2'], z=transformed_iris['component3'],color='species')
fig.show(renderer="svg")
or you can set the pio.renderers.default to svg:
pio.renderers.default = "svg"
Import these and this and it will work :
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.graph_objs as go
init_notebook_mode(connected=True)

networkx draw graph deprecated message

I am trying to draw a graph networkx using python 3.6 with Jupyter notebook and the network package with anaconda. But the graph is not drawing per the documentation, I am just getting a deprecated message.
CODE:
import networkx as nx
import csv
import matplotlib as plt
G = nx.read_pajek('Hi-tech.net')
nx.draw(G)
MESSAGE:
MatplotlibDeprecationWarning: pyplot.hold is deprecated.
Future behavior will be consistent with the long-time default:
plot commands add elements without first clearing the
Axes and/or Figure.
b = plt.ishold()
Future behavior will be consistent with the long-time default:
plot commands add elements without first clearing the
Axes and/or Figure.
plt.hold(b)
warnings.warn("axes.hold is deprecated, will be removed in 3.0")
To avoid this warning, I just simply replace
nx.draw(G)
by
nx.draw_networkx(G)
My Python is 3.4, Jupyter '1.0.0' and networkx '1.11'.
I was able to get rid of the message by going into the networkx library and simply placing # in front of the lines which produced the error.
I would infer the .hold() function is no longer necessary, nor does it need ot be replaced
I could get nx.draw(G) to work by adding the following line of command:
%matplotlib inline
As error suggest ... I change nx_pylab.py at 611
# if cb.is_numlike(alpha):
if isinstance(alpha,numbers.Number):
I just commented out the line 365 of file __init__.py in Lib\site-packages\matplotlib\cbook which reads
#deprecated('3.0', 'isinstance(..., numbers.Number)')

Resources