5

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.

  • 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 6 '17 at 7:24
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"
  • yeah I was the one that opened up that issue on github. haven't had a chance to check this workaround. – user3014097 May 17 '15 at 0:23
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")
  )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.