6

I have been trying to figure out what attribute is setting the background for inline plots in EIN. The background for the plot seems to always take the default background color for my color theme, even though I'm changing the default background color for the major mode that it's contained in. I.e.:

(defun switch-color ()
  "Switch default bg for ipython notebook."
  (face-remap-add-relative 'default '((:background "white"))))
(add-hook 'ein:notebook-multilang-mode-hook 'switch-color)

This works for everything except for the inline plots that are generated.

I have also tried editing matplotlibrc, and have been able to change the coloring for different parts of the plot (ticks, axes, etc) with the exception of the background.

I don't know enough about how the plots are generated inline to figure out where they're inheriting their background color from. I've looking through the M-x customize-group options for ein, but haven't been able to find anything that affects the inline plot background.

user3014097
  • 253
  • 1
  • 4
  • The background for the images generated is a transparency. The current answer works, but you can also set this in the matplotlibrc file if you want a one-off. It's a hassle, though, I agree. – Dodgie Jan 06 '17 at 07:24

2 Answers2

2

this was discussed on the emacs-ipython-notebook github recently. https://github.com/millejoh/emacs-ipython-notebook/issues/41

It seems like a bug in iPython, but for the moment there is a work around by setting the matplotlab rc parameters directly.

import matplotlib as mpl
mpl.rcParams["figure.facecolor"] = "white"
mpl.rcParams["axes.facecolor"] = "white"
mpl.rcParams["savefig.facecolor"] = "white"
Matt Savoie
  • 121
  • 3
0

I use this workaround in my init.el

(defadvice ein:insert-image (around ein-transparent-color-replacement activate)
  (ad-set-args 0 (append (ad-get-args 0) `(:background ,(face-attribute 'ein:cell-output-area :background))  )) ad-do-it)

;add some additional spacing. not essential
(defadvice ein:cell-append-display-data (around ein-transparent-color-replacement activate)
  (ein:insert-read-only  "\n ")
  ad-do-it
  (ein:insert-read-only "\n")
  )