Class: Numo::Gnuplot::PlotData
- Inherits:
-
Object
- Object
- Numo::Gnuplot::PlotData
- Defined in:
- lib/numo/gnuplot.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #cmd_str ⇒ Object
-
#data_format ⇒ Object
:nodoc: all.
- #data_str ⇒ Object
-
#initialize(*data) ⇒ PlotData
constructor
A new instance of PlotData.
- #line_str(i) ⇒ Object
Constructor Details
#initialize(*data) ⇒ PlotData
Returns a new instance of PlotData.
818 819 820 821 822 823 824 825 |
# File 'lib/numo/gnuplot.rb', line 818 def initialize(*data) if data.empty? raise ArgumentError,"no data" end @data = data.map{|a| a.flatten} @n = @data.map{|a| a.size}.min @text = true end |
Class Method Details
.array_shape(a) ⇒ Object
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'lib/numo/gnuplot.rb', line 872 def self.array_shape(a) if a.kind_of?(Array) is_2d = true is_1d = true size_min = nil a.each do |b| if b.kind_of?(Array) is_1d = false if b.any?{|c| c.kind_of?(Array)} is_2d = false elsif size_min.nil? || b.size < size_min size_min = b.size end else is_2d = false end break if !is_1d && !is_2d end if is_1d [a.size] elsif is_2d [a.size, size_min] else kernel_raise GnuplotError, "not suitable Array for data" end elsif a.respond_to?(:shape) a.shape else kernel_raise GnuplotError, "not suitable type for data" end end |
Instance Method Details
#cmd_str ⇒ Object
827 828 829 830 831 832 833 |
# File 'lib/numo/gnuplot.rb', line 827 def cmd_str if @text "'-'" else "'-' binary record=#{@n} format='%float64'" end end |
#data_format ⇒ Object
:nodoc: all
814 815 816 |
# File 'lib/numo/gnuplot.rb', line 814 def data_format @data_format || DATA_FORMAT end |
#data_str ⇒ Object
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
# File 'lib/numo/gnuplot.rb', line 835 def data_str if @text s = "" @n.times{|i| s << line_str(i)+"\n"} s + "e\n" elsif defined? Numo::NArray m = @data.size x = Numo::DFloat.zeros(@n,m) m.times{|i| x[true,i] = @data[i][0...@n]} x.to_string else s = [] @n.times{|i| s.concat @data.map{|a| a[i]}} s.pack("d*") end end |
#line_str(i) ⇒ Object
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/numo/gnuplot.rb', line 852 def line_str(i) @data.map do |a| v = a[i] case v when Float,Rational s = data_format % v when Numeric s = v.to_s else s = v.to_s if /"/ =~ s kernel_raise GnuplotError,"should not include double quotation in data" else s = '"'+s+'"' end end s end.join(" ") end |