holoviz-topics / imagen

ImaGen: Generic Python library for 0D, 1D and 2D pattern distributions
https://imagen.holoviz.org/
BSD 3-Clause "New" or "Revised" License
31 stars 16 forks source link

matplotlib get messed up due to import of holoviews #48

Closed zym1010 closed 8 years ago

zym1010 commented 8 years ago

Hi,

I've been using imagen for a while, for generating a bunch of stimuli in the lab. It's great. However, it has a side effect of importing holoview related stuff and messed up the default plotting style of matplotlib completely in jupyter notebook. Also, importing imagen seems to change the matplotlib backend to 'agg' silently, and it makes inline plot using vanilla matplotlib fail.

Is there any way to solve this? Thanks.

jbednar commented 8 years ago

Glad you are finding it useful. That's an excellent question! Historically, imagen had no dependence on holoviews, but it included certain files that we needed to develop further in holoviews, so we switched it around so that those files moved to holoviews and changed imagen to import them from there. So imagen only relies on a very small part of holoviews, and it should be very feasible to make sure we only import those parts and not any of the plotting-related functionality that would interact with matplotlib.

@jlstevens and @philippjfr, what's the status of being able to import the "core" bits of holoviews without any additional dependencies? Does this still require changes to holoviews, or were those changes already made a while back? I can't find a holoviews issue for this.

philippjfr commented 8 years ago

I'll have to think about it a bit. There should be a way to import holoviews without initializing the plotting backends and thereby changing the matplotlib options but afaik it isn't currently possible.

@jlstevens and @philippjfr, what's the status of being able to import the "core" bits of holoviews without any additional dependencies?

You can import the core bits of holoviews without any of the dependencies, the problem is that if the dependencies are available it will just go ahead and import it anyway. If we can defer the loading of the plotting backends until the holoviews notebook_extension is executed that would be ideal.

zym1010 commented 8 years ago

@philippjfr @jbednar thanks for quick response!

It seems to me that imagen only requires holoviews in terms of coordinate system. If this is truly the case, then I think it should be easily done, by factoring out those coordinate-related functions out of the plotting-related functions in holoviews, right?

jbednar commented 8 years ago

That's right; that's all that imagen requires. But imagen also has optional support for plotting via holoviews, and so we have to make sure that it's possible to avoid enabling that support, for people who do not want it, because of the side effects it has on matplotlib.

A while back I proposed adding a text-based backend for holoviews, which would help bypass some of these issues, but I found little interest at the time. :-/

zym1010 commented 8 years ago

@jbednar sounds great! so I guess a minimal way of fixing this problem would be somehow loading those plotting-related functions in imagen in a lazy fashion.

philippjfr commented 8 years ago

I don't think there is any way around modifying holoviews to ensure the plotting backends don't get loaded on import. We should do this anyway and it already is an existing issue in HoloViews (https://github.com/ioam/holoviews/issues/528). We're aiming for a HoloViews release later this week and that should be part of it.

zym1010 commented 8 years ago

@philippjfr thanks!

philippjfr commented 8 years ago

The PR fixing this in holoviews has now been merged and we'll have a new release later today. Closing.