Make pandas plot() show xlabel and xvalues

后端 未结 2 1201
不思量自难忘°
不思量自难忘° 2021-01-22 16:52

I am using the standard pandas.df.plot() function to plot two columns in a dataframe. For some reason, the x-axis values and the xlabel are not visible! There seem

相关标签:
2条回答
  • 2021-01-22 17:39

    This is a bug with Jupyter notebooks displaying pandas scatterplots that have a colorscale displayed while using Matplotlib as the plotting backend.

    @june-skeeter has a solution in the answers works. Alternatively, pass sharex=False to df.plot.scatter and you don't need to create subplots.

    import matplotlib.cm as cm
    import pandas as pd
    
    X = np.random.rand(10,3)
    
    df = pd.DataFrame(X,columns=['t','hlReference', 'STEP_STRENGTH'])
    
    df.plot.scatter(
        x='t', 
        y='hlReference', 
        c='STEP_STRENGTH', 
        cmap=cm.autumn,
        sharex=False
    )
    

    See discussion in this closed pandas issues. Which references the above solution in a related SO answer.

    Still an issue with pandas v1.1.0. You can track the issue here: https://github.com/pandas-dev/pandas/issues/36064

    0 讨论(0)
  • 2021-01-22 17:43

    Create your axes instance first and then send it as an argument to the plot()

    import matplotlib.cm as cm
    import pandas as pd
    
    
    X = np.random.rand(10,3)
    df = pd.DataFrame(X,columns=['t','hlReference', 'STEP_STRENGTH'])
    fig,ax1=plt.subplots()
    df.plot.scatter(x='t', y='hlReference', c='STEP_STRENGTH', cmap=cm.autumn,ax=ax1)
    

    0 讨论(0)
提交回复
热议问题