2016-06-21 2 views
1

제 3 변수를 사용하여 색상을 정의하는 다채로운 산포도를 만들려고합니다. 다음 코드를 사용하는 것이 간단합니다.색깔을 정의하기 위해 제 3 변수를 사용하여 파이썬 산란 컬러 플롯을 만들 때 색상이 없음

plt.scatter(mH, mA, s=1, c=mHc) 
plt.colorbar() 
plt.show() 

그러나 플롯의 프레임을 수정할 수있는 방법은 많지 않습니다. 나는 동시에 나는 음모의 프레임을 최적화하려고, 화려한 산포도를 만들기 위해 다음 코드를 시도하고있다 :

import numpy as np 
import math 
from matplotlib import rcParams 
import matplotlib.pyplot as plt 
from matplotlib.ticker import AutoMinorLocator 

fig, ax = plt.subplots() 

cax = ax.scatter(mH,mA,s=0.5,c=mHc) ### mH, mA, mHC are the dataset 
fig.colorbar(cax) 
minor_locator1 = AutoMinorLocator(6) 
minor_locator2 = AutoMinorLocator(6) 
ax.xaxis.set_minor_locator(minor_locator1) 
ax.yaxis.set_minor_locator(minor_locator2) 
ax.tick_params('both', length=10, width=2, which='major') 
ax.tick_params('both', length=5, width=2, which='minor') 
ax.set_xlabel(r'$m_H$') 
ax.set_ylabel(r'$m_A$') 
ax.set_xticks([300,600,900,1200,1500]) 
ax.set_yticks([300,600,900,1200,1500]) 

plt.savefig('mH_mA.png',bbox_inches='tight') 
plt.show() 

하지만 내가 가진 플롯은 흑백이다. 마커 크기 인수에 문제가있는 것처럼 보입니다. 그러나이를 수정하는 방법에 대해서는 잘 모릅니다. 작은 마커 크기를 갖고 싶습니다. 누구든지 나에게이 문제에 대한 접근을 제안 할 수 있습니다. 감사. enter image description here

답변

3

size=0.5 매우 작습니다. 아마도 마커 외곽선 만 보셨을 것입니다. 난 당신이 크기를 조금 증가 제안, 아마 마커 가장자리 스트로크를 해제 edgecolors="none"을 통과 할 것 :

import numpy as np 
from matplotlib import pyplot as plt 

n = 10000 
x, y = np.random.randn(2, n) 
z = -(x**2 + y**2)**0.5 

fig, ax = plt.subplots(1, 1) 
ax.scatter(x, y, s=5, c=z, cmap="jet", edgecolors="none") 

enter image description here

당신은 또한 alpha=를 사용하여 포인트를 반투명하게 실험 할 수 있습니다 매개 변수 :

ax.scatter(x, y, s=20, c=z, alpha=0.1, cmap="jet", edgecolors="none") 

enter image description here

얻을 어려울 수 있습니다 엄청난 겹치는 점이 많을 때 멋지게 보이게하는 흩 뿌려진 그림. 내가 대신 2 차원 히스토그램이나 윤곽 플롯으로 데이터를 플롯 유혹, 또는 분산 플롯과 등고선 플롯의 어쩌면 조합 될 것이다 :

density, xe, ye = np.histogram2d(x, y, bins=20, normed=True) 
ax.hold(True) 
ax.scatter(x, y, s=5, c=z, cmap="jet", edgecolors="none") 
ax.contour(0.5*(xe[:-1] + xe[1:]), 0.5*(ye[:-1] + ye[1:]), density, 
      colors='k') 

enter image description here

+0

덕분에 많이. 그것은 매우 도움이된다. –

관련 문제