该图绘制得很好,但我不能访问的Line2D对象。
下面的实施例的代码:
import pandas as pd
import numpy as np
from matplotlib import pyplot
df=pd.DataFrame({"col1":np.random.rand(10), "col2":np.random.rand(10)})
fig=pyplot.figure()
ax=fig.add_subplot(1,1,1)
ax=df.plot(kind="scatter", x="col1", y="col2", ax=ax)
ax.lines # the result is an empty list.
fig.show()
也ax.get_lines()
给出相同的结果,即没有线。当我直接与ax.scatter(...)
绘制同样的事情发生。
我认为这是你在找什么:
import pandas as pd
import numpy as np
from matplotlib import pyplot
from matplotlib.lines import Line2D
df=pd.DataFrame({"col1":np.random.rand(10), "col2":np.random.rand(10)})
fig=pyplot.figure()
ax=fig.add_subplot(1,1,1)
ax=df.plot(kind="scatter", x="col1", y="col2", ax=ax)
line = Line2D(df["col1"],df["col2"]) #create the lines with Line2D
ax.add_line(line) #add the lines to fig
fig.show()