Code Monkey home page Code Monkey logo

Comments (27)

glamp avatar glamp commented on August 17, 2024

Oh man this is extremely annoying. I think it's because the legend is actually "outside of the figure" if that makes sense. My hunch is that there's some sort of default config parameter that gets set somewhere that would fix this in 1 line of code. Maybe try stackoverflow or ask fperez?

from ggpy.

Carreau avatar Carreau commented on August 17, 2024
In [6]: %config InlineBackend
InlineBackend options
-------------------
...
InlineBackend.rc=<Dict>
    Current: {'font.size': 10, 'figure.figsize': (6.0, 4.0), 'figure.facecolor': 'white', 'savefig.dpi': 72, 'figure.subplot.bottom': 0.125, 'figure.edgecolor': 'white'}
    Subset of matplotlib rcParams that should be different for the inline
    backend.

??

from ggpy.

minrk avatar minrk commented on August 17, 2024

When IPython embeds a figure inline, it uses bbox_inches='tight'. My guess is that the tight layout calculation is excluding the legend. How is the legend added to the figure?

from ggpy.

minrk avatar minrk commented on August 17, 2024

I opened matplotlib/matplotlib#2530 regarding the cutoff issue.

from ggpy.

glamp avatar glamp commented on August 17, 2024

cool thanks.

from ggpy.

mdbecker avatar mdbecker commented on August 17, 2024

FYI, a workaround for this is to call ggsave and save the plot to a file. Obviously this won't give it to you inline in ipynb, but it works if you don't mind viewing the plot outside ipynb.

from ggpy.

ptwobrussell avatar ptwobrussell commented on August 17, 2024

Wow, I did not realize that --pylab=inline automatically would work with ggplot in IPython Notebook. This is incredible! Can't wait to start using it in my notebooks.

👍

from ggpy.

jankatins avatar jankatins commented on August 17, 2024

A workaround could be to implement __repr__html() (or __repr__png()?). That could then use something else than the tight layout. Not sure if that clashes with the default showing of matplotlib plots in ipython, though...

from ggpy.

jankatins avatar jankatins commented on August 17, 2024

There are also some features in gridlayout, which can adjust the tight layout to include some space for such things as titles (and additional artists?). Worst case could be to add a new axis where the legend artist is added to.

http://matplotlib.org/users/tight_layout_guide.html#use-with-gridspec

from ggpy.

tdsmith avatar tdsmith commented on August 17, 2024

Not exactly a long-term solution but if end-users just want to make it work for them right now, commenting out "bbox_inches='tight'" in the IPython source (core/pylabtools.py line ~109 for me) seems to work fine.

Does it make sense to ask the IPython folk if they have a good rationale for keeping that parameter?

from ggpy.

minrk avatar minrk commented on August 17, 2024

We have a good reason for having it (better layout of matplotlib figures without unnecessary frame padding when the figures are inline), but the issues associated with tight layout might suggest that we should turn it off anyway, or at least allow it to be turned off.

from ggpy.

jankatins avatar jankatins commented on August 17, 2024

There seems to be a a workaround until it is fixed in matplotlib (see matplotlib/matplotlib#2530 (comment)) but that also means that only a more recent version of matplotlib will work.

from ggpy.

pelson avatar pelson commented on August 17, 2024

Fixed in matplotlib master matplotlib/matplotlib#2689.

from ggpy.

jml avatar jml commented on August 17, 2024

I'm pretty sure I'm still getting this issue:

  • matplotlib (1.4.2)
  • ggplot (0.6.5)
  • ipython (2.3.0)

I get the legend when I have %matplotlib osx but not when I have %matplotlib inline.

from ggpy.

jml avatar jml commented on August 17, 2024

Disregard. I somehow have 2 versions of matplotlib on my system.

from ggpy.

overnin avatar overnin commented on August 17, 2024

@jml i have same issus on osx 10.9 with matplotlib (1.4.2) and ggplot (0.6.5), the legend doesn't appear. Is there any specific environment variable to setup?

Here is my plot:

plot = ggplot(df_hdiff, aes(x='Hour', y='value', color='variable')) \
    + geom_point() + geom_line() + xlab("Hour of the day") + ylab("Average Number of Riders")\
    + ggtitle("Entries and Exits vs Hour") + scale_color_manual(values=['blue', 'red'])

from ggpy.

overnin avatar overnin commented on August 17, 2024

Issue fixed with last version of ggplot from github.

from ggpy.

trebsirk avatar trebsirk commented on August 17, 2024

legend still not showing on osx using
ggplot==0.6.5
ipython==2.3.1
matplotlib==1.4.2
pandas==0.15.2
i'm using %matplotlib inline.
this is so annoying. I basically can't use ggplot for anything.

from ggpy.

overnin avatar overnin commented on August 17, 2024

@trebsirk is the problem persistent when you install the latest commit of ggplot pip install git+git://github.com/yhat/ggplot.git?

from ggpy.

ntldrake avatar ntldrake commented on August 17, 2024

I'm having the same issue with ggplot==0.6.6

from ggpy.

trebsirk avatar trebsirk commented on August 17, 2024

@overnin i used pip install ggplot --upgrade for the latest version, and it chopped off the legend. i have also tried with 0.5.9 with the same results. Is there a different version of matplotlib that could fix this?

from ggpy.

overnin avatar overnin commented on August 17, 2024

@trebsirk i don't exactly remember how to fix the issue. Install matpotlib from git may help.

from ggpy.

ntldrake avatar ntldrake commented on August 17, 2024

It only seems to be happening with faceting.

# Doesn't work
p = ggplot(aes(x='month_id', y='mins_per_video', color='platform_value'), data=df_final2) + \
    geom_line() + \
    ggtitle("%s Minutes Per Video by Platform & Operating System" % web_name) + \
    xlab("Month ID") + \
    ylab("Minutes Per Video") + \
    facet_wrap('device_value', scales='fixed') + \
    xlim(178,181)

p
# Works
p2 = ggplot(aes(x='month_id', y='mins_per_viewer', color='platform_value'), data=df_final2[(df_final2.device_value=="Smartphone")]) + \
    geom_line() + \
    ggtitle("%s Minutes Per Viewer by Platform & Operating System" % web_name) + \
    xlab("Month ID") + \
    ylab("Minutes Per Viewer") + \
    xlim(178,181)


p2

from ggpy.

PaulMest avatar PaulMest commented on August 17, 2024

This code straight from the ggplot examples does not show legends with ggplot 0.6.5:

    from ggplot import meat
    meat_lng = pd.melt(meat, id_vars=['date'])

    gplt = gg.ggplot(gg.aes(x='date', y='value', colour='variable'), data=meat_lng) + \
            gg.geom_line() + \
            gg.theme({'theme_position':'right'})

    gg.ggsave(plot=gplt, filename="gplt.png", width=12, height=3, dpi=100)

Environment: ggplot 0.6.5 installed via:

$ pip install ggplot

I was able to fix by pip installing straight from master:

$ pip uninstall ggplot
$ pip install git+git://github.com/yhat/ggplot.git

The legend now shows up.

My environment:

  • Mac OS X Yosemite.
  • Python 2.7.8
  • Matplotlib 1.4.3
  • ggplot 0.6.6

from ggpy.

relativistic avatar relativistic commented on August 17, 2024

I had same problem as @PaulMest. Same version numbers, except for using OSX Mavericks. I also had installed it using ggplot.

His suggestion of installing directly from the git master fixed it for me as well. Apparently there is a problem with the version pip pulls by default?

from ggpy.

rcompton avatar rcompton commented on August 17, 2024

Same as @relativistic , clone direct from github and it works

from ggpy.

edoardovivo avatar edoardovivo commented on August 17, 2024

I am experiencing the same issue.

My environment:

  • CentOS release 6.6
  • matplotlib: 1.5.1
  • ggplot: 0.6.8
  • jupyter-core: 4.1.0

My code:

p = ggplot(df_PN_melt, aes(x="M", y="value", colour="variable")) + \
    geom_point(size=40) + \
    geom_line(size=3) + \
    facet_wrap("Option", ncol=2) + \
    scale_color_manual(breaks=my_breaks )
print p

This does NOT produce a legend neither with ggsave nor with inline visualization in Jupyter.

I see the last comment here is one year old, so I suppose cloning directly from github was a workaround that should be outdated by now.

Any idea?

Thank you

from ggpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.