How to enable display of Matplotlib graphs with PyCharm? - matplotlib

When I run a program with PyCharm, it doesn't display graphs made with Matplotlib. E.g.:
import matplotlib.pyplot as plt
[...]
plt.imshow(montage(W / np.max(W)), cmap='coolwarm')
I tried calling
plt.interactive(False)
first, but it didn't make a difference.
Running the same program with ipython3, the graphs are displayed.

I set a default back-end for my system in matplotlibrc (TkAgg), and that did the trick.

The below code worked for me:
in pycharm-community-2018.2.2
import matplotlib.pyplot as plt
df.boxplot(column='ApplicantIncome')
plt.show()

Related

ImportError: cannot import name '_path'

i must install matplotlib on a offline PC with python 3.5....to run some scripts. I copy the lib to the Right path on the offline PC....all other lib like reportlab are running. But if i trie to write something with matplotlib.pyplot as plt i got the Error Message "ImportError:cannot Import 'path'".
a the first step i
Import matplotlib
matplotlib.use('aggs')
Import matplotlib.pyplot as plt
the biggest Problem i cant download something on this offline pc.
So i am rly new to write some codes with python so pls dont jugde me guys =)
So the frist step was delet the old libs and use older versions of matplotlib
actuel i use 3.0.2.
i copy the Folders matplotlib, matplotlib-3.0.2.dist-info and matplotlib-3.0.2-py3.5-nspkg.pth
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9.5, 6), dpi=450)
ax = fig.gca()
ax.set_xticks(np.arange(tick_scale_x))
ax.set_yticks(np.arange(tick_scale_y))
plt.title(dia_title, fontsize=20, color='black')
plt.xlabel(axis_label_x)
plt.ylabel(axis_label_y)

Matplotlib: emoji font does not work when using backend_pdf

I want to use the emoji-font "Symbola.ttf" to label my plots. This does work when I use plt.show(). But it does not work when using the backend_pdf. Only two emojis are shown in a mixed up order.
example images:
when using plt.show():
when using the backend_pdf:
example code:
Here is my code to produce these examples:
import matplotlib.backends.backend_pdf
import matplotlib.pyplot as plt
import emoji
from matplotlib.font_manager import FontProperties
emojis = [emoji.EMOJI_UNICODE[e] for e in list(emoji.EMOJI_UNICODE.keys())[620:630]]
prop = FontProperties(fname='./Symbola.ttf', size=30)
# backend_pdf plot
pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
plt.xticks(range(len(emojis)), emojis, fontproperties=prop)
pdf.savefig()
pdf.close()
# plt.show() plot
plt.xticks(range(len(emojis)), emojis, fontproperties=prop)
plt.show()
I'm running this on a Linux machine.
I think I have found the problem. It seems that my Symbola.ttf was broken. When I use this .ttf file everything works great.

Visualize my matplotlib output

I run a several code and get
Draw = pf.plot_drawdown_periods(returns, top=5).set_xlabel('Date')
type(Draw)
<matplotlib.text.Text at 0x7fb063733f90>
How can make my result visible in different ways?
You need to explicitly call pyplot.show() to display the graphics.
import matplotlib.pyplot as plt
pf.plot_drawdown_periods(returns, top=5).set_xlabel('Date')
plt.show()

Use ipywidgets to interatively find best position matplotlib text

I am interested in using the interact function to use a slider to adjust the position of text in a matplotlib plot (you know, instead of adjusting the position, running the code, and repeating 1000 times).
Here's a simple example of a plot
import matplotlib.pyplot as plt
x=0.2
y=0.9
plt.text(x, y,'To move',size=19)
plt.show()
and some interact code
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
def f(x):
return x
interact(f, cx=0.2)
I'm wondering how I can combine these to generate a plot with the text along with a slider that will interactively move the text based on the specified value for x. Is this possible? What if I want to do the same for y?
Thanks in advance!
Here you go:
%matplotlib inline
import matplotlib.pyplot as plt
from ipywidgets import interact
def do_plot(x=0.2, y=0.9):
plt.text(x, y,'To move',size=19)
plt.show()
interact(do_plot)

How to show matplotlib charts in browser (html)?

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