هل هناك طريقة لرسم تغيير اليوم على نطاق زمني بالساعة على محور X؟

StackOverflow https://stackoverflow.com/questions/4209876

  •  25-09-2019
  •  | 
  •  

سؤال

أنا أستخدم gnuplot لرسم البيانات التي تعتمد على الوقت.

تؤخذ العينات كل 5 دقائق أو نحو ذلك ولدي 200 عينة.

أنا أرسم هذه مع محور X منسق إلى

set format x "%H:%M"

من الناحية المثالية ، أرغب في طباعة التاريخ عندما يعبر المحور السيني منتصف الليل ... ولكن فقط عندما يعبر منتصف الليل. شيء مثل:

22:00   22:30   23:00   23:30   00:00   00:30   01:00
                              2010-11-17

أي من المعلمين gnuplot هناك يعرف طريقة للقيام بذلك؟

هل كانت مفيدة؟

المحلول

إنه سؤال جيد.

ما يلي يعتمد على T16Web.lanl.gov/kawano/gnuplot/plot4-e.html#5.12.

تحتاج أساسا إلى رسم البيانات مرتين ، مرة واحدة لكل محور. في المرة الثانية التي أرسم فيها البيانات ، أقوم بنقل المؤامرة الفعلية خارج النطاق (عن طريق طرح 1000) بحيث يتم رسم مؤامرة واحدة فقط. يقوم البرنامج النصي SHELL التالي بإنشاء البيانات ويؤسس كما في الرسم البياني أدناه.

أتمنى أن يكون هذا ما تريد.

#!/bin/bash

echo "2010-11-17 13:30:01,1
2010-11-17 13:30:12,3.1
2010-11-18 13:30:23,2.1
2010-11-19 13:30:34,4" > two_axis.dat

gnuplot<<EOF
## Plot a second axis with the day rather than the time
## Based on example from http://t16web.lanl.gov/Kawano/gnuplot/plot4-e.html#5.12.

##  make a png file
set term png small
set output "two_axis.png"
## reduce the size of the main plot to allow for second axis
set size 1.0,0.8
set bmargin 0
set lmargin 3  # set space given to axis
## The data for the second plot will be set to be out of range,
##     Need to explicitly set range here.
set yrange [0:5] 

set multiplot

## Main plot, raised slightly
set origin 0,0.2
set datafile separator "," 
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S" 
set format x "%H:%M" 

## Need to set xrange so that the axes of the two plots match exactly
set xrange["2010-11-17 12:00:00":"2010-11-19 14:00:00"]

## The main plot!
plot "./two_axis.dat" using 1:2 with lines

## Now want to draw second axis with just the days
set origin 0,0.1
## Dont want any ytics or minor xtics or drawn axes
set noytics
unset mxtics
unset border
## Don't want axis mirrored, want tick scales to zero so that it vanishes,
##    And some format for the days of the week axis
set xtics nomirror scale 0 format "%Y-%m-%d"

##  Specify the tics interval in seconds 1 day = 86400 seconds
set xtics "2010-11-01 00:00:00", 86400,   "2010-12-01 00:00:00"

## Replot the graph but this time with the data shifted out of the way,
##  we don't want to replot the data (difficult to align with previous plot) - 
##  we just want the axis
plot "./two_axis.dat" using 1:(\$2-1000) with lines notitle

## clean up
unset multiplot
set output
set term pop
EOF

alt text

أتمنى لك كل خير،

توم

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top