2014-10-31 2 views
2

ggplot을 사용하여 파이썬에서 시계열 데이터를 플로팅하려하고 스케일을 수정할 수 없습니다.파이썬 ggplot datetime에 축 범위 설정

여기 내 가장 최근의 노력입니다 - 처음에는 원하는 최대 및이 xMin과 x 축의 최소 값과 XMAX 설정 : 내 시간 변수를 플롯하려고 dataframe의 fishdf에서, 그리고

xmin=pd.to_datetime('2011-04-01')
xmax=pd.to_datetime('2011-08-01')

를 (' tottime '- x 축) 숫자 변수 (에 대한'RX ', y 축) :이 잘 작동

fig=(ggplot(fishdf,aes('tottime','rx')) + \ 
    geom_line() + \ 
    geom_point() + \ 
    ggtitle(PIT) + \ 
    scale_x_date(breaks='7 days', 
     labels=date_format('%m -%d'), 
     limits=(xmin,xmax))) + \ 
    scale_y_continuous(limits=(0,235)) 
outfig= r"C:\a\Projects\Shad Telemetry\Connecticut River\CumDat\Python\figs\%s.png"%(PIT) 
ggsave(fig,outfig) 

나는 한계 = 명령을 포함하지만,하지 않을 때 한계와 I 오류가 발생했습니다

TypeError : float가 필요합니다.

xmin 및 xmax를 설정/포맷하는 다양한 방법을 시도했지만 작동하지 않는 것 같습니다. 간단한 해결책이 있습니까? 나는 다른 곳에서 관련 질문을 보았다. 그러나 대답은 나를 위해 일하지 않는 것 (또는 대답이 없다)

답변

0

내가 결정할 수있는 한, 이것은 파이썬의 ggplot의 버그이다. 내 데이터를 R에 이식 할 수 있었고 비슷한 코드를 실행할 수있었습니다. IT는 다음과 같이 복잡합니다 (다른 여러 항목). 그러나 본질적으로이 코드는 공통 축을 사용하여 4 가지 데이터 유형에서 500 개의 플롯을 생성하고 작업 할 수있었습니다. 그래서 명확히하기 위해, 이것은 파이썬이 아닌 R 코드입니다 :

xlimits<-as.POSIXct(c('2011-04-15','2011-08-01'),tz='GMT') 
for(i in as.vector(PITs2011$PIT)) 
{ 
    plot<-paste("C:\\etc\\",i,".png", sep="") 
    png(plot,width=7.5, height=5, units="in",res=300) 
    title=paste(i,'Release Location=',Tags$ReleaseLocation[Tags$PIT==i]) 
    Tagi=Tags[Tags$PIT==i,] 
    PITi=Clean2011[Clean2011$PIT==i,] #THIS SHOULD REALLY BE Radioi 
    nr<-nrow(PITi) 
    TIRISi=FWRES[FWRES$PIT==i,] 
    nt<-nrow(TIRISi) 
    Mobilei=Mobile[Mobile$PIT==i,] 
    nm<-nrow(Mobilei) 
    p<-'' 
    if((nt==0) & (nm==0) & (nr==0)) { #First group has only radio data and also Tags data (true for all) 
    p<-ggplot(data=Tagi,aes(x=time, y=rx)) +#Need to modify this for fish with only ReleaseTime (no radio) 
    geom_point(data=Tagi,aes(color='PIT'), shape=21, size=4) + 
    scale_colour_manual(name="", 
     values = c("Radio"="blue", "PIT"="red"))+ 
    scale_x_datetime(limits=xlimits)+ 
    scale_y_continuous(limits=c(0,235))+ 
    ggtitle(title) 
    }else if # etc...I then subsetted for the various data types that were available for each plot.