IT TIP

MatPlotLib : 동일한 산점도의 여러 데이터 세트

itqueen 2020. 11. 30. 20:31
반응형

MatPlotLib : 동일한 산점도의 여러 데이터 세트


동일한 산점도에 여러 데이터 세트를 플로팅하고 싶습니다.

cases = scatter(x[:4], y[:4], s=10, c='b', marker="s")
controls = scatter(x[4:], y[4:], s=10, c='r', marker="o")

show()

위는 가장 최근의 scatter()

나는 또한 시도했다 :

plt = subplot(111)
plt.scatter(x[:4], y[:4], s=10, c='b', marker="s")
plt.scatter(x[4:], y[4:], s=10, c='r', marker="o")
show()

Axes동일한 서브 플롯에 계속 그리 려면 객체에 대한 참조가 필요합니다 .

import matplotlib.pyplot as plt

x = range(100)
y = range(100,200)
fig = plt.figure()
ax1 = fig.add_subplot(111)

ax1.scatter(x[:4], y[:4], s=10, c='b', marker="s", label='first')
ax1.scatter(x[40:],y[40:], s=10, c='r', marker="o", label='second')
plt.legend(loc='upper left');
plt.show()

여기에 이미지 설명 입력


나는 똑같은 문제가 있었기 때문에이 질문을 보았습니다. 받아 들여지는 대답은 잘 작동하지만 matplotlib 버전 2.1.0에서는 참조를 사용하지 않고 한 플롯에 두 개의 산점도를 갖는 것이 매우 간단합니다.Axes

import matplotlib.pyplot as plt

plt.scatter(x,y, c='b', marker='x', label='1')
plt.scatter(x, y, c='r', marker='s', label='-1')
plt.legend(loc='upper left')
plt.show()

모르겠습니다. 잘 작동합니다. 정확한 명령 :

import scipy, pylab
ax = pylab.subplot(111)
ax.scatter(scipy.randn(100), scipy.randn(100), c='b')
ax.scatter(scipy.randn(100), scipy.randn(100), c='r')
ax.figure.show()

여기에 설명 된대로 데이터가 Dataframe에 표시되는 경우 Pandas에서도이 작업을 쉽게 수행 할 수 있습니다.

http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html#scatter-plot

참고 URL : https://stackoverflow.com/questions/4270301/matplotlib-multiple-datasets-on-the-same-scatter-plot

반응형