wt列是数字,但是这里要把它当成str,而不是数字
坐标轴也需要对小数位进行处理
数字太多,为了横轴展示开,旋转60度
from plotnine import * from plotnine.data import mtcars x_tick = [str(round(s, 2)).format("%.2f") for s in list(mtcars['wt'].unique())] mtcars['wt'] = mtcars['wt'].astype(str) p1 = (ggplot(mtcars,aes('wt','mpg',group='factor(gear)',color='factor(gear)')) + geom_line() + geom_point(aes(shape='factor(gear)')) #+ ylim(0.75,1) + scale_x_discrete(labels=x_tick) + labs(x='wt') + theme(axis_text_x = element_text(rotation=60,size=9)) ) print(p1)