making matplotlib graphs look like R by default?

后端 未结 8 1734
自闭症患者
自闭症患者 2021-01-29 23:02

Is there a way to make matplotlib behave identically to R, or almost like R, in terms of plotting defaults? For example R treats its axes pretty differently from

8条回答
  •  日久生厌
    2021-01-29 23:21

    Here's a blog post you may be interested to read:

    Plotting for Pandas GSoC2012

    http://pandasplotting.blogspot.com/

    Decided to try to implement a ggplot2 type plotting interface...Not yet sure how much of the ggplot2 functionality to implement...

    The author forked pandas and built what looks like quite a lot of ggplot2-style grammar for pandas.

    Density Plots

    plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
    plot.add(rplot.TrellisGrid(['sex', 'smoker']))
    plot.add(rplot.GeomHistogram())
    plot.render(plt.gcf())
    

    The pandas fork is here: https://github.com/orbitfold/pandas

    Seems like meat of the code to make the R-influenced graphics is in a file called rplot.py which can be found in a branch in the repo.

    class GeomScatter(Layer):
        """
        An efficient scatter plot, use this instead of GeomPoint for speed.
        """
    
    class GeomHistogram(Layer):
        """
        An efficient histogram, use this instead of GeomBar for speed.
        """
    

    Link to the branch:

    https://github.com/orbitfold/pandas/blob/rplot/pandas/tools/rplot.py

    I thought this was really cool, but I can't figure out if this project is being maintained or not. The last commit was a while ago.

提交回复
热议问题