So I found the following code here:
from matplotlib import pyplot as plt from matplotlib.patches import Rectangle someX, someY = 0.5, 0.5 plt.figure() currentAxis = plt.gca() currentAxis.add_patch(Rectangle((someX - .1, someY - .1), 0.2, 0.2,alpha=1)) plt.show()
Which gives:
But what I want is a rectangle with only a blue border and inside of it to be transparent. How can I do this?
Matplotlib automatically arrives at the minimum and maximum values of variables to be displayed along x, y (and z axis in case of 3D plot) axes of a plot. However, it is possible to set the limits explicitly by using set_xlim() and set_ylim() functions.
We can add rectangle by using Rectangle() function in patches module. The Rectangle function takes the location/size of the rectangle you need, left position, bottom location, and width & height.
You can easily fill in the area between values in a Matplotlib plot by using following functions: fill_between(): Fill the area between two horizontal curves. fill_betweenx(): Fill the area between two vertical curves.
You just need to set the facecolor
to the string 'none' (not the python None
)
from matplotlib import pyplot as plt from matplotlib.patches import Rectangle someX, someY = 0.5, 0.5 fig,ax = plt.subplots() currentAxis = plt.gca() currentAxis.add_patch(Rectangle((someX - 0.1, someY - 0.1), 0.2, 0.2, alpha=1, facecolor='none'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With