Comments (27)
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.
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.
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.
I opened matplotlib/matplotlib#2530 regarding the cutoff issue.
from ggpy.
cool thanks.
from ggpy.
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.
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.
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.
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.
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.
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.
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.
Fixed in matplotlib master matplotlib/matplotlib#2689.
from ggpy.
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.
Disregard. I somehow have 2 versions of matplotlib on my system.
from ggpy.
@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.
Issue fixed with last version of ggplot from github.
from ggpy.
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.
@trebsirk is the problem persistent when you install the latest commit of ggplot pip install git+git://github.com/yhat/ggplot.git
?
from ggpy.
I'm having the same issue with ggplot==0.6.6
from ggpy.
@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.
@trebsirk i don't exactly remember how to fix the issue. Install matpotlib from git may help.
from ggpy.
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.
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.
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.
Same as @relativistic , clone direct from github and it works
from ggpy.
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)
- [Feature Request]: Plot directly onto a matplotlib axis HOT 1
- the numbers squeeze on the x-axis or y-axis
- Wrong code
- Is this project dead? HOT 16
- "metaclass conflict" error when using ggplot 0.6.8 with six 1.10.0+
- Import does not work with pandas 0.23.4
- unable to import in jupyter notebook HOT 5
- Warning received when using color aesthetic with geom_point
- Import issue in jupyter notebook
- AttributeError: module 'pandas' has no attribute 'tslib' HOT 35
- Can't facet on variable with more than 9 levels
- facet_grid fail with a category type
- facet_grid repeat x-axis
- pandas sort issue
- How about make it available with dfply?
- Link to an actively developed project called "plotnine" which provides ggplot functionality in python.
- ggplot installs for python3.9.1.0, but import ggplot gets error re pandas attribute tslib HOT 2
- plot multiple geoms on top of each other
- Looking for `ggplot` substitution HOT 2
- Questions about Copilot + Open Source Software Hierarchy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggpy.