2017-01-12 3 views
1

을 pyplot . 축이 보이지 않으면 레이블이 표시되지 않으므로 축 레이블로 시도한 모든 항목이 실패합니다.하기 matplotlib 색상 코딩 지점이 위도/경도 산포도에서 2D 분산없이 축 추가, 공유 축 레이블

이러한 오류가없는 작업 코드는 아래와 같습니다. 축 테두리, 라벨의 표시 점과 ticklabels :

import pandas as pd 
import matplotlib.pyplot as plt 

df = pd.read_csv("_test.csv") 
power = df['n'] 
lat = df['latitude'] 
lon = df['longitude'] 

df = pd.read_csv("shifted3.csv") 
power = df['n'] 
lat = df['latitude'] 
lon = df['longitude'] 
plt.subplot(121) 
plt.scatter(lon, lat, c=power,s=65, vmin=0, vmax=3700) 
# c= sets how the points are coloured, s= point size, vmin/max colour lims 
plt.title('a) AGW') 
plt.ylim(ymin=51.44,ymax=51.73) 
plt.xlim(xmin=1.42, xmax=1.63) 
plt.axis('off') 
cbar = plt.colorbar() 
cbar.ax.set_yticklabels(['0','','','','','','','','','3600']) 

plt.subplot(122) 
#plt.figure(figsize=(5,10)) 
plt.scatter(lon, lat, c=power,s=65, vmin=0, vmax=3700) 
# c= sets how the points are coloured, s= point size, vmin/max colour lims 
plt.title('b) no event') 
plt.xlim(xmin=2.23, xmax=2.45) 
plt.ylim(ymax=52.09) 
plt.axis('off') 
# # 
cbar = plt.colorbar() 
cbar.ax.set_yticklabels(['0','','800','','1600','','2400','','','3600']) 
cbar.set_label('Power (kW)', rotation=270, labelpad=+12) 
#labelpad + moves legend to right, - to left 

plt.show() 
+0

을 제공, 모두 함께이 퍼팅? http://stackoverflow.com/questions/29041326/3d-plot-with-matplotlib-hide-axes-but-keep-axis-labels – periphreal

+1

정말 달성하고자하는 것을 이해하기가 어렵습니다. "나는 축을 갖고 싶지 않습니다."- 당신이 보여주는 플롯은 축을 가지고 있지 않습니다. "...하지만 x 축과 y 축에 공유 레이블이 있습니다"x와 y는 어떻게 레이블을 공유합니까? 그 라벨은 어디에 앉을까요? – ImportanceOfBeingErnest

+0

사과 @ImportanceOfBeingErnest, 나는 서브 플로트 아래에 공유 된 x 레이블과 두 개의 플롯의 왼쪽에 하나의 y 축을 의미했습니다. –

답변

2

plt.axis("off") 사용하면 모든 것을 죽인다.

그 중 일부를 유지하려면 개별적으로 꺼야합니다.
틱은 ax.xaxis.set_visible(False)을 통해 보이지 않게 할 수 있습니다.
국경은 ax.spines["bottom"].set_visible(False)을 통해 보이지 않게 설정할 수 있습니다.

전체 그림 아래의 레이블은 plt.figtext(x, y, text)을 통해 설정할 수 있습니다.

이 답변으로 문제가 않습니다

import pandas as pd 
import matplotlib.pyplot as plt 
import numpy as np 


power = np.random.rand(32)*3600 
lat = 51.45 + 0.26*np.random.rand(32) 
lon = 1.44 + 0.18*np.random.rand(32) 


plt.subplot(121) 
plt.scatter(lon, lat, c=power,s=65, vmin=0, vmax=3700) 
# c= sets how the points are coloured, s= point size, vmin/max colour lims 
plt.title('a) AGW') 
plt.ylim(ymin=51.44,ymax=51.73) 
plt.xlim(xmin=1.42, xmax=1.63) 
#plt.axis('off') 
cbar = plt.colorbar() 
cbar.ax.set_yticklabels(['0','','','','','','','','','3600']) 

ax = plt.gca() 
ax.set_ylabel("Some y label") 

#Make x axis and all spines but left one invisible 
ax.xaxis.set_visible(False) 
for position in ["right", "top", "bottom"]: 
    ax.spines[position].set_visible(False) 
# Only show ticks on the left spine 
ax.yaxis.set_ticks_position('left') 

plt.subplot(122) 
#plt.figure(figsize=(5,10)) 
plt.scatter(lon, lat, c=power,s=65, vmin=0, vmax=3700) 
# c= sets how the points are coloured, s= point size, vmin/max colour lims 
plt.title('b) no event') 
plt.xlim(xmin=1.42, xmax=1.63) 
plt.ylim(ymin=51.44,ymax=51.73) 
#plt.axis('off') 
# # 
cbar = plt.colorbar() 
cbar.ax.set_yticklabels(['0','','800','','1600','','2400','','','3600']) 
cbar.set_label('Power (kW)', rotation=270, labelpad=+12) 
#labelpad + moves legend to right, - to left 
ax = plt.gca() 
ax.xaxis.set_visible(False) 
ax.yaxis.set_visible(False) 
for position in ["left","right", "top", "bottom"]: 
    ax.spines[position].set_visible(False) 
# Add some text below the subplots 
plt.figtext(0.5, 0.05, "Some x label beneath the whole figure", ha="center") 

plt.show() 

enter image description here