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

  • SEARCH
  • Home
  • 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 3948106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:20:07+00:00 2026-05-20T01:20:07+00:00

Consider the following code: from numpy import log2 import matplotlib.pyplot as plt xdata =

  • 0

Consider the following code:

from numpy import log2
import matplotlib.pyplot as plt

xdata = [log2(x)*(10/log2(10)) for x in range(1,11)]
ydata = range(10)
plt.plot(xdata, ydata)
plt.show()

This produces the following plot: The plot I do not want My question is, how can I modify this, so that the plot, with the exact same data as input, appears as a straight line? This basically requires scaling the x-axis appropriately, but I cannot figure how to do this. The reason for doing this is that I am displaying a function that changes very little at the beginning, but starts to fluctuate more towards the end of the valid interval, so I want to have a higher horizontal resolution towards the end. If anyone can propose an alternative solution to my approach, feel free to do so!

  • 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-20T01:20:07+00:00Added an answer on May 20, 2026 at 1:20 am

    Here is how it is done. A good example to follow. You just subclass the ScaleBase class.

    Here’s your transform. It’s not too complicated when you whittle out all the custom formatters and stuff. Just a little verbose.

    from numpy import log2
    import matplotlib.pyplot as plt
    
    from matplotlib import scale as mscale
    from matplotlib import transforms as mtransforms
    
    class CustomScale(mscale.ScaleBase):
        name = 'custom'
    
        def __init__(self, axis, **kwargs):
            mscale.ScaleBase.__init__(self)
            self.thresh = None #thresh
    
        def get_transform(self):
            return self.CustomTransform(self.thresh)
    
        def set_default_locators_and_formatters(self, axis):
            pass
    
        class CustomTransform(mtransforms.Transform):
            input_dims = 1
            output_dims = 1
            is_separable = True
    
            def __init__(self, thresh):
                mtransforms.Transform.__init__(self)
                self.thresh = thresh
    
            def transform_non_affine(self, a):
                return 10**(a/10)
    
            def inverted(self):
                return CustomScale.InvertedCustomTransform(self.thresh)
    
        class InvertedCustomTransform(mtransforms.Transform):
            input_dims = 1
            output_dims = 1
            is_separable = True
    
            def __init__(self, thresh):
                mtransforms.Transform.__init__(self)
                self.thresh = thresh
    
            def transform_non_affine(self, a):
                return log2(a)*(10/log2(10))
    
            def inverted(self):
                return CustomScale.CustomTransform(self.thresh)
    
    
    mscale.register_scale(CustomScale)
    
    xdata = [log2(x)*(10/log2(10)) for x in range(1,11)]
    ydata = range(10)
    plt.plot(xdata, ydata)
    
    plt.gca().set_xscale('custom')
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: from PIL import Image, ImageDraw, ImageFont def addText(img, lTxt): FONT_SIZE
Consider the following snippet of Python code: from sqlalchemy import * from sqlalchemy.orm import
Consider the following code: #main.py From toolsmodule import * database = foo #toolsmodule database
Consider the following code (from here , with the number of tests increased): from
Consider the following code (from a requirement that says that 3 is special for
Consider the following code snippet from .NET 4.0 library: private T[] array; private static
Consider the following code: Dim sql = SELECT * FROM MyTable WHERE value1 =
Consider the following code. DECLARE @sql VARCHAR(MAX) SELECT @sql = 'SELECT * FROM caseinformation'
Consider the following code? I was wondering, if I change it from (Function body
Consider the following code I wrote: import Control.Monad increasing :: Integer -> [Integer] increasing

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.