Search code examples
python-2.7scatter-plotpython-ggplot

python ggplot scatter emphasize


I do a scatter plot with python 2.7 ggplot. I want the background steelblue but emphasize some points but failed. Can some one help me on that.

Code Piece:

from ggplot import *
chart = ggplot( df_color, aes(x='x-tsne', y='y-tsne') )\
                 + geom_point(color='steelblue',size=70,alpha=0.8)\
                 + geom_point(data=df_color.loc[self.GoI,:],aes(x='x-tsne', y='y-tsne'), colour="red",size=5)\
                 + ggtitle("tSNE dimensions")

The error follows:

line 154
+ geom_point(data=df_color.loc[self.GoI,:],aes(x='x-tsne', y='y-tsne'), colour="red",size=5)\
SyntaxError: non-keyword arg after keyword arg

Solution

  • A rule of thumb in Python is that a function call of type f(a,b,c=something, d,...) will not work as you call non-keyword (d) after a keyword (c). Here order is important, while the order of keyword arguments is not, assuming that you give them in the form keyword=arg. Python also allows you to give them just as arg, which then requires the correct order.

    Long story short: read the error message.