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 7162103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:40:47+00:00 2026-05-28T13:40:47+00:00

I am building a variable resolution ruler control for a data visualization program. I

  • 0

I am building a variable resolution ruler control for a data visualization program. I want it to show axes tick labels depending on zoom level.

For exemple, with a very wide zoom, it would plot only [100, 200, 300] tick labels. Then if I close zoom, it would show, say, [10, 15, 20, 25] labels.

The numbers would always be multiple of 5 or 10. So, a partial “rounding grid” would be [1, 5, 10, 50, 100, 500, 1000, 5000], but that would grow infinitely for both sides (including decimal numbers.

The question is: given an arbitrary positive floating point number, how could I ‘floor’ it to the first smaller number in the grid?

(This would allow me to set the granularity of the tick labels according to the plotter’s zoom level/scale).

Mind that:

  • The grid is “infinite” (that’s why I didn’t use sorting and other list methods);
  • There is no fixed set of values to the floating point number, except it’s always positive and non-zero.

  • (EDIT) The resolution IS NOT SYMMETRIC, the tick intervals are, say, [1,5,10,50,100,500,…], the increment multipliers being, alternately, 2 and 5!

Thanks for reading

  • 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-05-28T13:40:48+00:00Added an answer on May 28, 2026 at 1:40 pm

    If the most significant digit is<5, use 1 and (k-1) zeros where k is the length of the number, else use 1 and (k-1) zeros. The following function works.

    import numpy as np
    def truncate(x):
        length = 0
        if x>=1:
            while x>=10:
                length+=1
                x/=10
        else:
            while x<1:
                length-=1
                x*=10
        r = max(0,-length) 
        if x<5:
            return round(np.power(10.0,length),r)
        else:
            return round(5*np.power(10.0,length),r)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a simple C++ program and I want to temporarily substitute a system
I'm building text balloons to display variable length messages in Flash. My question is
I'm building a simple java Servlet which passes categories using a URL variable into
I am loading some XML data, building it into an unordered list and displaying
i need help building a function that display an associative array and i want
I'm building a pseudo-variable parser in PHP to allow clean and simple syntax in
I am building a program that randomly generates a number then this number is
I am building a jQuery plugin and i'm using a variable in it which
I'm building few command-line utilities in Xcode (plain C, no Cocoa). I want all
I have a fairly trivial static variable question. I'm building out a solution that

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.