Place rectangle in drawing


Rt Rt

For this question I am referring to this example : https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html

I would like to replace the sinogram with a simple rectangle plot that doesn't show the coordinate system .

To be precise, I want to change this part of the original code:

class MyStaticMplCanvas(MyMplCanvas):
    """Simple canvas with a sine plot."""

    def compute_initial_figure(self):
        t = arange(0.0, 3.0, 0.01)
        s = sin(2*pi*t)
        self.axes.plot(t, s)

I found the rectangle class in Matplotlib : https://matplotlib.org/devdocs/api/_as_gen/matplotlib.patches.Rectangle.html#examples-using-matplotlib-patches-rectangle

This should be an easy task. But I've tried a lot myself without success. One of my many attempts looks like: (but it doesn't work)

class MyStaticMplCanvas(MyMplCanvas):
    """Simple canvas with a rectangle plot."""
    def compute_initial_figure(self):
        x = 10
        y = 20
        width = 10
        height = 20

        fig,ax = plt.subplots(1)
        rect = mpatches.Rectangle((x, y), width, height)

        ax.add_patch(rect)
        self.axes.plot(rect)

Can someone help me? Any help would be greatly appreciated!

User 3419537

You can add Rectangleto self.axesuse add_patch. This method does not automatically change the limits of the axis. Consider where you are trying to place Rectanglethe patch.

class MyStaticMplCanvas(MyMplCanvas):

    """Simple canvas with a rectangle plot."""
    def compute_initial_figure(self):
        x = 10
        y = 20
        width = 10
        height = 20

        rect = mpatches.Rectangle((x, y), width, height)
        self.axes.add_patch(rect)
        # Change limits so we can see rect
        self.axes.set_xlim((0, 50))
        self.axes.set_ylim((0, 50))

Related


Place a rectangle inside another rectangle and place the element

Bill Taha I'm trying to write a resume template just to learn the basics about HTML and CSS. However, I'm running into a problem when placing one rectangle inside another. I've been searching for hours and how to fix this but not sure why it doesn't appear at

Place a rectangle inside another rectangle and place the element

Bill Taha I'm trying to write a resume template just to learn the basics about HTML and CSS. However, I'm running into a problem when placing one rectangle inside another. I've been searching for hours and how to fix this but not sure why it doesn't appear at

Place a rectangle inside another rectangle and place the element

Bill Taha I'm trying to write a resume template just to learn the basics about HTML and CSS. However, I'm running into a problem when placing one rectangle inside another. I've been searching for hours and how to fix this but not sure why it doesn't appear at

Place a rectangle inside another rectangle and place the element

Bill Taha I'm trying to write a resume template just to learn the basics about HTML and CSS. However, I'm running into a problem when placing one rectangle inside another. I've been searching for hours and how to fix this but not sure why it doesn't appear at

Place a rectangle inside another rectangle and place the element

Bill Taha I'm trying to write a resume template just to learn the basics about HTML and CSS. However, I'm running into a problem when placing one rectangle inside another. I've been searching for hours and how to fix this but not sure why it doesn't appear at

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

Pygame not drawing rectangle on click

Moeez Ali I am new to pygame and I am making a simple game. In this code I am trying to draw a rectangle when the mouse is at a certain position, but it fails to draw when I print anything import pygame pygame.init() res = (600,600) screen = pygame.display.

place text inside a rectangle

Holapress We have a webapp where we draw a map for an event we are hosting, and now we are trying to input data saved to a database into indesign to be able to edit and print from there. The webversion map looks like this: The code I am using for this atm is<R

Tkinter drawing rectangle not working as expected

Vahn Toan: WIDTH = HEIGHT = 800 DIMENSION = 8 SQ_SIZE = HEIGHT / DIMENSION IMAGES = {} def draw_board(): colors = ["white", "black"] for r in range(DIMENSION+1): for c in range(DIMENSION+1): canvas.create_rectangle(100, 100, r * (

svg rectangle border not drawing correctly

Tom O'Brien Just started using svg. I'm trying to draw a simple rectangle with a border, but it seems like the border is giving me a shadow-like effect somehow. It seems that the right and bottom borders are drawn much thicker than the top and left borders. We

Tkinter drawing rectangle not working as expected

Vahn Toan: WIDTH = HEIGHT = 800 DIMENSION = 8 SQ_SIZE = HEIGHT / DIMENSION IMAGES = {} def draw_board(): colors = ["white", "black"] for r in range(DIMENSION+1): for c in range(DIMENSION+1): canvas.create_rectangle(100, 100, r * (

OpenGL drawing rectangle with mouse drag?

dawn I'm trying to draw a shape similar to a tool in paint, drag it in it, and when the mouse is released it will draw the shape. Currently what my program does is that if you click it, it has a rubber band to show you the shape, but nothing is drawn when you

Switch between drawing a rectangle and freehand

username I'm having some problems with my Java paint program. I have a JComboBoxplace where I can choose to draw a rectangle or freehand. These objects will be added to ArrayList. I'd like to be able to switch between drawing rectangles and freehand, then back

Get the drawing rectangle of the UIImageView image

Wolfrevo Is there an easy way to get the visible/drawn rectangle of a UIImageView image? rect must be correct for any chosen contentMode and should take into account masksToBounds. Example 1: A 100x100 UIImageView with a 200x200 image, masksToBounds=YES, conte

Writing extensions for Drawing.Rectangle

powerful Drawing.Rectangle has methods Dim r As Drawing.Rectangle = Drawing.Rectangle.FromLTRB(...) I want to write an extension method similar to this function. The extension method will create a rectangle containing all the given points. I wrote such a meth

svg rectangle border not drawing correctly

Tom O'Brien Just started using svg. I'm trying to draw a simple rectangle with a border, but it seems like the border is giving me a shadow-like effect somehow. It seems that the right and bottom borders are drawn much thicker than the top and left borders. We

Load PDF in Canvas and Drawing Rectangle

Southhurst S I'm trying to build a web page to display a PDF file inside a canvas and allow the user to draw rectangles. Below is the code I am trying. The problem is that the mouse events also move outside the canvas. How to limit mouse drag events only insid

Leaflet drawing on rectangle throws error

Caius I am leaflet + leaflet-draw + @ngx-leaflet + @ngx-leaflet-drawusing in an Angular application. I've tried everything , changed versions, didn't import modules .forRoot(), didn't add js files to my angular.jsonfiles , removed node_modules, reinstalled the

Drawing rectangle doesn't work

ByoTic Can you explain what's wrong with this code? Because it doesn't draw anything. Isn't it supposed to draw a rectangle in my form? Thanks! public partial class Form1 : Form { public Form1() { InitializeComponent(); Graphics g = t

Switch between drawing a rectangle and freehand

username I'm having some problems with my Java paint program. I have a JComboBoxplace where I can choose to draw a rectangle or freehand. These objects will be added to ArrayList. I'd like to be able to switch between drawing rectangles and freehand, then back

Tkinter drawing rectangle not working as expected

Vahn Toan: WIDTH = HEIGHT = 800 DIMENSION = 8 SQ_SIZE = HEIGHT / DIMENSION IMAGES = {} def draw_board(): colors = ["white", "black"] for r in range(DIMENSION+1): for c in range(DIMENSION+1): canvas.create_rectangle(100, 100, r * (

Get the drawing rectangle of the UIImageView image

Wolfrevo Is there an easy way to get the visible/drawn rectangle of a UIImageView image? rect must be correct for any chosen contentMode and should take into account masksToBounds. Example 1: A 100x100 UIImageView with a 200x200 image, masksToBounds=YES, conte

svg rectangle border not drawing correctly

Tom O'Brien Just started using svg. I'm trying to draw a simple rectangle with a border, but it seems like the border is giving me a shadow-like effect somehow. It seems that the right and bottom borders are drawn much thicker than the top and left borders. We

OpenGL drawing rectangle with mouse drag?

dawn I'm trying to draw a shape similar to a tool in paint, drag it in it, and when the mouse is released it will draw the shape. Currently what my program does is that if you click it, it has a rubber band to show you the shape, but nothing is drawn when you

Load PDF in Canvas and Drawing Rectangle

Southhurst S I'm trying to build a web page to display a PDF file inside a canvas and allow the user to draw rectangles. Below is the code I am trying. The problem is that the mouse events also move outside the canvas. How to limit mouse drag events only insid