Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7882337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:15:37+00:00 2026-06-03T04:15:37+00:00

I am searching for an easy way to plot about 10 points and rectangles

  • 0

I am searching for an easy way to plot about 10 points and rectangles to be able to see where my algorithm goes wrong. I had a look at gnuplot, but it seems it is particularly bad a plotting rectangles.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:15:39+00:00Added an answer on June 3, 2026 at 4:15 am

    SVG (MDN Tutorial) is a very simple text-based (XML) format that you can emit easily using Ruby without any SVG library and view in any modern web browser. Here’s one example:

    SVG Points via String Interpolation

    points = (0..5).map{ [rand(100)-50,rand(100)-50] }
    
    puts <<ENDSVG
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="-100 -100 200 200">
    #{points.map{ |x,y| "<circle cx='#{x}' cy='#{y}' r='3' />" }.join("\n")}
    </svg>
    ENDSVG
    

    Output: http://jsfiddle.net/xwnVY/


    If you want to be more structured than string interpolation:

    SVG Points Using Nokogiri XML Builder

    require 'nokogiri' # gem install nokogiri
    b = Nokogiri::XML::Builder.new do |doc|
      doc.svg xmlns:"http://www.w3.org/2000/svg", viewBox:"-100 -100 200 200" do
        points.each do |x,y|
          doc.circle r:3, cx:x, cy:y
        end
      end
    end
    puts b.to_xml
    

    Save the output as “foo.svg” and open it in a modern web browser to view.


    Drawing Rects

    To draw rects, you can use any of:

    <rect transform="rotate(45)" x="0" y="0" width="100" height="200" />
    <polygon points="0,0 100,0 100,100 0,100" />
    <path d="M0,0 L100,0 100,100 0,100 Z" />
    

    The polygon may be the easiest to produce if you want to connect arbitrary points that are not axis-aligned without worrying about transforms. Note that while I’ve shown the coordinates above in the format x,y x,y for clarity, SVG will also accept x,y,x,y or x y x y, if those are easier for your code to generate.


    A Bit of Formatting

    If you want to draw outlines instead of filled shapes, you can add this CSS in your SVG:

    <style>
      rect, polygon, path { fill:none; stroke:black; stroke-width:1px }
    </style>
    

    Using Haml for the XML

    Finally, Haml is another option that you might consider for making your XML without an SVG-specific library:

    @points = (0..7).map{ [rand(100)-50,rand(100)-50] }
    
    require 'haml'
    puts Haml::Engine.new(<<ENDHAML).render(self)
    %svg(xmlns="http://www.w3.org/2000/svg" viewBox="-100 -100 200 200")
      :css
        circle { fill:orange }
        rect, polygon, path {
          fill:none; stroke:black;
          vector-effect:non-scaling-stroke
        }
      - @points.each_slice(4) do |rect|
        %polygon{ points:rect.join(" ") }
      - @points.each do |x,y|
        %circle{r:3, cx:x, cy:y}
    ENDHAML
    

    Output: http://jsfiddle.net/xwnVY/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm searching for an easy way to translate url strings into arrays of controller/action
i've spent some time searching and there is probably is an easy way to
When searching the web it is easy to find this way to print out
I have been searching for an easy way to get the ServerName of the
I'm searching for a light-weight, fast and easy way to handle Inter Process Communication
I'm searching for an easy way to reuse code in xcode 4.3. Is there
I'm currently searching for a really easy way to get simple Java Objects persistent
Inverted index is designed to be fast for searching but not that easy for
I'm looking for a RichTextBox with syntax highlighting! Sounds easy but I'm searching since
Searching with '[Delphi] source control' didn't return much, so here goes: For those of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.