-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQUEST] Jupyter Inline Plots #17
Comments
Looks like adding import ipykernel.pylab.backend_inline, mplcairo.base
ipykernel.pylab.backend_inline.new_figure_manager = mplcairo.base.new_figure_manager to your ipython_config.py should work, can you confirm? |
I'm trying to follow Brienna's tutorial on plotting emojis with matplotlib. But I got segmentation fault error when running the script from the command line. This is the script I run import faulthandler; faulthandler.enable()
# Set the backend to use mplcairo
import platform
print(platform.mac_ver())
print(platform.python_version())
import matplotlib, mplcairo
print('Default backend: ' + matplotlib.get_backend())
matplotlib.use("module://mplcairo.macosx")
print('Backend is now ' + matplotlib.get_backend())
print('matplotlib version: ' + matplotlib.__version__)
# IMPORTANT: Import these libraries only AFTER setting the backend
import matplotlib.pyplot as plt, numpy as np
from matplotlib.font_manager import FontProperties
# Load Apple Color Emoji font
prop = FontProperties(fname='/System/Library/Fonts/Apple Color Emoji.ttc')
# Set up plot
freqs = [301, 96, 53, 81, 42]
labels = ['😊', '😱', '😂', '😄', '😛']
plt.figure(figsize=(12,8))
p1 = plt.bar(np.arange(len(labels)), freqs, 0.8, color="lightblue")
plt.ylim(0, plt.ylim()[1]+30)
# Make labels
for rect1, label in zip(p1, labels):
height = rect1.get_height()
plt.annotate(
label,
(rect1.get_x() + rect1.get_width()/2, height+5),
ha="center",
va="bottom",
fontsize=30,
fontproperties=prop
)
# plt.show()
plt.savefig("e.png") This is the output I got after enable
I installed mplcairo, pycairo using pip and cairo using brew
I also noticed you solved her issue a year ago. What other information I can provide to help to debug the issue? |
I tested on ubuntu 18.04 and it worked perfect as long as I copy the ttc file to it. # Set the backend to use mplcairo
import matplotlib, mplcairo
print('Default backend: ' + matplotlib.get_backend())
matplotlib.use("module://mplcairo.base")
print('Backend is now ' + matplotlib.get_backend())
# IMPORTANT: Import these libraries only AFTER setting the backend
import matplotlib.pyplot as plt, numpy as np
from matplotlib.font_manager import FontProperties
# Load Apple Color Emoji font
prop = FontProperties(fname='./Apple Color Emoji.ttc')
# Set up plot
freqs = [301, 96, 53, 81, 42]
labels = ['😊', '😱', '😂', '😄', '😛']
plt.figure(figsize=(12,8))
p1 = plt.bar(np.arange(len(labels)), freqs, 0.8, color="lightblue")
plt.ylim(0, plt.ylim()[1]+30)
# Make labels
for rect1, label in zip(p1, labels):
height = rect1.get_height()
plt.annotate(
label,
(rect1.get_x() + rect1.get_width()/2, height+5),
ha="center",
va="bottom",
fontsize=30,
fontproperties=prop
)
plt.savefig("e.png") |
I think this issue is unrelated to the original one in this thread? If so, please open a separate issue to keep discussions tidy. |
OK. Because I tried to set |
Closing this for lack of reply on the original poster, and because the second issue is tracked on #18. Feel free to request a reopen if necessary. |
I'm using Jupyter Lab and I added these lines in my config file (jupyterlab_config.py): import ipykernel.pylab.backend_inline, mplcairo.base
ipykernel.pylab.backend_inline.new_figure_manager = mplcairo.base.new_figure_manager However, the inline plot does not show up. I started Jupyter Lab using the command |
When I use the mplcairo backend, my plots do not appear inline in Jupyter (I'm not talking about the inline widget here, just inline PNGs).
Is there anyway to get the inline PNGs, given Cairo supports PNG export anyway?
The text was updated successfully, but these errors were encountered: