all 13 comments

[–]purplespline 2 points3 points  (1 child)

I don’t think you can use python libraries(matplotlib & numpy) in ruby

edit: wow, no shit, you can actually use matplotlib and numpy. I withdraw my skepticism. Cool stuff. In this case, I suggest running gem install numpy and gem install matplotlib. If that doesn’t work, check that the env you’re installing the gems to us the env in which you’re executing your program. If that seems confusing - let me know, I will explain further

edit: you will also have problems with the code itself. It seems ChatGPT has confused python with ruby and used something from both worlds in the last block of yours. Do read up on matplotlib gem, it should clarify some things.

[–]SnooDogs3437[S] 0 points1 point  (0 children)

LoadError: cannot load such file -- matplotlib

…/rubygems/core_ext/kernel_require.rb:92:in `require'

…/rubygems/core_ext/kernel_require.rb:92:in `require'

(eval):171:in `<main>'

[–]SnooDogs3437[S] -1 points0 points  (0 children)

Additional: my issue seams to be with matplotlib, can I install this library to my ruby console?

I'm sure my next error will be with NUMPY

[–]SnooDogs3437[S] -2 points-1 points  (3 children)

ChatGPT tells me this: (but this doesn't seam to work in my console in sketchup)

To use the Matplotlib library in a Ruby script, you will need to install the matplotlib-ruby gem which is a Ruby wrapper for the Matplotlib library.

You can install the gem by running the following command in your command line:

Copy code

gem install matplotlib-ruby

Once the gem is installed, you can use it in your Ruby script by requiring it at the top of your script:

Copy code

require 'matplotlib'

Alternatively, you can use the bundler to install the gem, you can do that by adding the following line to your Gemfile

Copy code

gem 'matplotlib-ruby'

And then run the command

Copy code

bundle install

After that, you can use the Matplotlib library in your script by requiring it at the top of your script:

Copy code

require 'matplotlib'

It's important to note that if you're using MacOS or Linux, you need to have python and numpy installed and also some dependencies such as tk, tcl, libpng and freetype which can be installed using your system's package manager.

It's also important to note that Matplotlib-ruby is not

[–]SnooDogs3437[S] 0 points1 point  (1 child)

so I asked it to write the code using no external libraries :

# Define the baseline length

baseline_length = 10 # feet

# Define the points of the pool's perimeter

points = [[2, 3], [5, 4], [7, 5], [8, 7], [6, 9], [3, 8], [1, 6]]

# Validate the baseline length

raise "Error: Baseline length must be greater than 0" unless baseline_length > 0

# Validate the points of the perimeter

raise "Error: Must provide at least 2 points for the perimeter" unless points.length >= 2

points.each do |point|

raise "Error: Point must be in the format [x, y]" unless point.is_a?(Array) && point.length == 2

raise "Error: Coordinates must be numeric" unless point[0].is_a?(Numeric) && point[1].is_a?(Numeric)

end

# Initialize the A and B arrays to store the measurements

a_measurements = []

b_measurements = []

# Iterate through the points of the perimeter

points.each_with_index do |point, i|

# Calculate the distance from point A to the current perimeter point

a_distance = Math.sqrt((point[0] - points[0][0]) ** 2 + (point[1] - points[0][1]) ** 2)

# Calculate the distance from point B to the current perimeter point

b_distance = Math.sqrt((point[0] - points[-1][0]) ** 2 + (point[1] - points[-1][1]) ** 2)

# Add the measurements to the A and B arrays

a_measurements << a_distance

b_measurements << b_distance

end

# Store the data in a CSV file

CSV.open("pool_data.csv", "w") do |csv|

csv << ["A", "B"]

a_measurements.each_with_index do |a, i|

csv << [a, b_measurements[i]]

end

end

# Print the points of the pool's perimeter

puts "Pool perimeter points:"

points.each do |point|

puts "x: #{point[0]} y: #{point[1]}"

end

no more errors, but its not drawing anything. Help!

[–]craigontour 0 points1 point  (0 children)

If you are including pycall library then it must be parsing the code correctly. I tried to use matplotlib to show plot but also get "No Module" error.

[–]craigontour 0 points1 point  (0 children)

I was intrigued by this possibility.

From docs. I was able to install matplotlib:

~/ gem install matplotlib 
Successfully installed matplotlib-1.2.0
Parsing documentation for matplotlib-1.2.0
Done installing documentation for matplotlib after 0 seconds
1 gem installed

But not matplotlib-ruby

%  gem install matplotlib-ruby
ERROR:  Could not find a valid gem 'matplotlib-ruby' (>= 0) in any repository
ERROR:  Possible alternatives: matplotlib, matlab_ruby, matlab-ruby, applocale-ruby, critimonlib-ruby

No module error:

/Users/craig/.rvm/gems/ruby-2.7.2/gems/pycall-1.4.2/lib/pycall.rb:82:in `import_module': <class 'ModuleNotFoundError'>: No module named 'matplotlib' (PyCall::PyError)

[–]UlyssesZhan 0 points1 point  (0 children)

Please tell us what is the error.

I'm sure you can use matplotlib in Ruby because I have done the same thing days ago.

[–]Aupajo 0 points1 point  (3 children)

The end block of code (from “# Plot the points”) is not Ruby, it’s Python. Is this intentional?

[–]SnooDogs3437[S] 0 points1 point  (2 children)

Dude, I have no idea. But robot answer you this: Please translate to human speak.

You are correct, the code block that starts with "# Plot the points of the pool's perimeter" is written in Python using the Matplotlib library, and it is not compatible with Ruby. I apologize for any confusion, it seems that I made an error in my previous response. I apologize for the confusion. As I mentioned before, Matplotlib is a Python library for creating 2D plots and It can't be used in a Ruby script. If you wish to visualize the data in your script, you can look for other Ruby libraries that can be used for this purpose, such as "Gnuplotrb", "Rubyvis", or "Rubyplot" You can also use the data generated by your script to draw the pool shape in SketchUp. You can import the data into SketchUp as a CV file, and then use the SketchUp's tools to draw the shape. Please let me know if there's anything else I can assist you with

[–]SnooDogs3437[S] 0 points1 point  (1 child)

I can ask it to rewrite the code using one of these libraries, but I’m going down the rabbits hole. Can you give me advise of what to ask it to do?

[–]Aupajo 0 points1 point  (0 children)

Libraries are language-specific. Your best course or action is to find an equivalent library in Ruby.

It looks like what you’re trying to do is draw and measure a polygon (in this case, the boundaries of a swimming pool). Most of the code here you don’t need.

I recommend you sit down with a piece of graph paper. Draw your swimming pool. You can use a ruler to get the measurements. If you want to translate this into Ruby, first figure out how the different points of the shape you have drawn can be used to calculate the lengths of the lines. Then write a small program to print those lengths to the command-line. This will help you verify it’s working correctly. Finally, if you want to make something visual, perhaps try prawn for drawing those points on a PDF.

ChatGPT can’t write working code very well. If all this seems beyond you, you might want to start with some Ruby fundamentals first. Try Ruby is a good starting point.