4

ggplot を使用して Python で時系列データをプロットしようとしていますが、スケールを修正できません。

これが私の最近の取り組みです。最初に、x 軸の目的の最大値と最小値を xmin と xmax として設定します。

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

次に、データフレーム fishdf から、時間変数 (「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)   

これは、limits= コマンドを含めない場合は正常に機能しますが、制限を使用するとエラーが発生します

TypeError: float が必要です

xmin と xmax を設定/フォーマットするさまざまな方法を試しましたが、うまくいかないようです。簡単な解決策はありますか?他の場所で関連する質問を見たことがありますが、答えがうまくいかないようです (または答えがありませんか?)

4

1 に答える 1

1

私が確認した限りでは、これは Python の ggplot のバグです。データを R に移植し、非常によく似たコードを実行することができました。IT は次の (複数の他のもの) よりも複雑ですが、本質的にこのコードは機能し、すべて共通の軸を持つ 4 つのデータ型から 500 のプロットを生成することができました。明確にするために、これは Python ではなく 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.
于 2015-01-25T01:18:33.473 に答える