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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:58:31+00:00 2026-06-05T22:58:31+00:00

This is a very direct follow-up on this question . Using matplotlib , I’d

  • 0

This is a very direct follow-up on this question.

Using matplotlib, I’d like to be able to place a sort of “highlighting bar” over a range of data markers that I know will all be in a straight horizontal line.

This bar/rectangle should be slightly taller than the markers and contain them, something like this for the three markers below:

enter image description here

In order to be a sensible highlighting bar, it needs to have the following two traits:

  • If the plot is panned, the bar moves with the markers (so it always covers them).
  • If the plot is zoomed, the bar’s display height doesn’t change (so it always is slightly taller than the markers).

If it is helpful to know, these markers have no meaningful y values (they are plotted all at y=-1), only meaningful x values. Therefore, the height of the bar is meaningless in data coordinates; it merely needs to be always just tall enough to enclose the markers.

  • 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-05T22:58:32+00:00Added an answer on June 5, 2026 at 10:58 pm

    Great question! This was a good challenge and requires a combination of things to achieve.

    Firstly, we need to invent a transform which will return the device coordinates of a pre-defined value plus an offset based on the given point. For instance, if we know we want the bar to be at x_pt, y_pt, then the transform should represent (in pseudo code):

    def transform(x, y):
        return x_pt_in_device + x, y_pt_in_device + y
    

    Once we have done this, we could use this transform to draw a box of 20 pixels around a fixed data point. However, you only want to draw a box of fixed pixel height in the y direction, but in the x direction you would like standard data scaling.

    Therefore, we need to create a blended transform which can transform the x and y coordinates independently. The whole code to do what you are asking:

    import matplotlib.pyplot as plt
    import matplotlib.patches as mpatches
    import matplotlib.path as mpath
    import matplotlib.transforms as mtrans
    
    import numpy as np
    
    
    class FixedPointOffsetTransform(mtrans.Transform):
        """
        Always returns the same transformed point plus
        the given point in device coordinates as an offset.
        """
        def __init__(self, trans, fixed_point):
            mtrans.Transform.__init__(self)
            self.input_dims = self.output_dims = 2
            self.trans = trans
            self.fixed_point = np.array(fixed_point).reshape(1, 2)
    
        def transform(self, values):
            fp = self.trans.transform(self.fixed_point)
            values = np.array(values)
            if values.ndim == 1:
                return fp.flatten() + values
            else:
                return fp + values
    
    
    plt.scatter([3.1, 3.2, 3.4, 5], [2, 2, 2, 6])
    
    ax = plt.gca()
    fixed_pt_trans = FixedPointOffsetTransform(ax.transData, (0, 2))
    
    xdata_yfixed = mtrans.blended_transform_factory(ax.transData, fixed_pt_trans)
    
    
    x = [3.075, 3.425] # x range of box (in data coords)
    height = 20 # of box in device coords (pixels)
    path = mpath.Path([[x[0], -height], [x[1], -height],
                       [x[1], height],  [x[0], height],
                       [x[0], -height]])
    patch = mpatches.PathPatch(path, transform=xdata_yfixed,
                               facecolor='red', edgecolor='black',
                               alpha=0.4, zorder=0)
    ax.add_patch(patch)
    
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

note: this is a direct follow up to this previous question I have very
I'm using this very handy plugin to sort elements. But comparing elements on a
This is probably a very trivial question, but I haven't been able to find
I am trying to build something very similar to like this using django activity
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
Direct Question : Is it possible to enable syntax highlighting for CUDA 4.0 in
I will be very direct with my question. I have been developing web applications
I am very much confused in this question. Which of the following advantages does
Ok, this is a very interesting question and there may not be any easy
I'm very new at this, I'd really like some help with this problem: First

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.