2015-01-17 3 views
0

matplotlib에 두 개의 다른 커브를 플롯하려하지만 플롯 중 하나가 산산이 있어야하거나 점을 연결하는 선이 없어야합니다. 이 작업을 수행 할 여지가 있습니까? 지금, 내 플로팅 내 코드는 다음과 같습니다 그러나matplotlib에서 2 y 축에 산포를 사용합니다. [Python]

fig, ax1 = plt.subplots() 

ax2 = ax1.twinx() 
ax1.plot(epoch, list_of_gas, 'b') 
ax2.plot(temp_times, temperatures, 'r') 

ax1.set_ylabel('Pressure (torr)', color='b') 
ax2.set_ylabel('Temperature (Celcius)', color='r') 

ax1.set_title(folder + ' - ' + gas) 
ax1.set_xlabel('time (seconds)') 
ax1.set_xlim([0, 1000000]) 
ax2.set_ylim([0,425]) 
ax1.set_yscale('log') 
ax1.set_ylim([ymin,ymax]) 

plt.show() 

, 나는 ax1.scatter (시대, list_of_gas, 'B')를 원하지만 당신은 2 개 축과 분산을 사용할 수 없습니다. 누구든지이 문제를 해결할 방법을 알고 있습니까? 점들을 연결하는 선을 제거하는 것처럼? 언급 한 바와 같이, = '없음'ls='none', or the longer 이는 linestyle :

답변

2

당신은 확실히 twinx 상황에서 scatter 플롯 할 수 있습니다 : 당신은 데이터 포인트를 연결하는 선을 제거하고자한다면, 또한

import numpy as np 
import matplotlib.pyplot as plt 

x, y = np.random.random((2,50)) 
fig, ax1 = plt.subplots() 
ax2 = ax1.twinx() 
ax1.scatter(x,y, c='b') 
x.sort() 
ax2.plot(x, np.sqrt(y)+y, c='r') 

을, 당신은 옵션을 추가 할 수 있습니다 matplotlib documentation. matplotlib은 대부분의 파이썬 라이브러리와 마찬가지로 현명한 기본값을 선택했습니다. plot에 대한 일반 호출의 경우 해당 기본값은 ls='-'이며 연결된 회선이 생성됩니다.

관련 문제