Gmagick Gmagick::flopimage (void)Parameters:this function takes no parameters.Return Value:This function returns a failed Gmagick object.Errors / Exceptions:this the function throws a GmagickException on error.The following programs illustrate the Gmagick::flopimage() functionin PHP:Program 1:
Original image:
< tbody> php
// Create a Gmagick object
$gmagick
=
new
Gmagick (
’ https://media.engineerforengineer.org/wp -content / uploads / tech.png ’
);
// Using the flopimage() function
$gmagick
-> flopimage();
header (
’ Content-type: image / png’
);
// Display image
echo
$gmagick
;
?>
Output: Program 2: < tbody> php
// Create a GmagickDraw object
$draw
=
new
GmagickDraw();
// Create GmagickPixel
$strokeColor
=
new
GmagickPixel (
’Red’
);
$fillColor
=
new
GmagickPixel (
’Green’
);
// Set the color, opacity of the image
$draw
-> setStrokeOpacity (1);
$draw
-> setStrokeColor (
’Red’
);
$draw
-> setFillColor (
’Green’
);
// Set the width and height of the image
$draw
-> setStrokeWidth (7);
$draw
-> setFontSize (72);
// Function for drawing a circle
$draw
-> circle (250, 250, 100, 150);
$gmagick
=
new
Gmagick();
$gmagick
-> newImage (500, 500,
’White’
);
$gmagick
-> annotateimage (
$draw
, 50, 60, 54,
’GeeksForGeeks’
);
$gmagick
-> setImageFormat (
"png"
);
$gmagick
-> drawImage (
$draw
);
// Using the flopimage() function
$gmagick
-> flopimage();
// Display the output image
header (
"Content-Type: image / png"
);
echo
$gmagick
-> getImageBlob();
?>
Output: Link : http://php.net/manual/en/gmagick.flopimage.php
PHP Gmagick flopimage () Function circle: Questions
How to do a scatter plot with empty circles in Python?
2 answers
In Python, with Matplotlib, how can a scatter plot with empty circles be plotted? The goal is to draw empty circles around some of the colored disks already plotted by scatter()
, so as to highlight them, ideally without having to redraw the colored circles.
I tried facecolors=None
, to no avail.
Answer #1
From the documentation for scatter:
Optional kwargs control the Collection properties; in particular:
edgecolors:
The string ‘none’ to plot faces with no outlines
facecolors:
The string ‘none’ to plot unfilled outlines
Try the following:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(60)
y = np.random.randn(60)
plt.scatter(x, y, s=80, facecolors="none", edgecolors="r")
plt.show()
Note: For other types of plots see this post on the use of markeredgecolor
and markerfacecolor
.
plot a circle with pyplot
2 answers
surprisingly I didn"t find a straight-forward description on how to draw a circle with matplotlib.pyplot (please no pylab) taking as input center (x,y) and radius r. I tried some variants of this:
import matplotlib.pyplot as plt
circle=plt.Circle((0,0),2)
# here must be something like circle.plot() or not?
plt.show()
... but still didn"t get it working.
Answer #1
You need to add it to an axes. A Circle
is a subclass of an Patch
, and an axes
has an add_patch
method. (You can also use add_artist
but it"s not recommended.)
Here"s an example of doing this:
import matplotlib.pyplot as plt
circle1 = plt.Circle((0, 0), 0.2, color="r")
circle2 = plt.Circle((0.5, 0.5), 0.2, color="blue")
circle3 = plt.Circle((1, 1), 0.2, color="g", clip_on=False)
fig, ax = plt.subplots() # note we must use plt.subplots, not plt.subplot
# (or if you have an existing figure)
# fig = plt.gcf()
# ax = fig.gca()
ax.add_patch(circle1)
ax.add_patch(circle2)
ax.add_patch(circle3)
fig.savefig("plotcircles.png")
This results in the following figure:
The first circle is at the origin, but by default clip_on
is True
, so the circle is clipped when ever it extends beyond the axes
. The third (green) circle shows what happens when you don"t clip the Artist
. It extends beyond the axes (but not beyond the figure, ie the figure size is not automatically adjusted to plot all of your artists).
The units for x, y and radius correspond to data units by default. In this case, I didn"t plot anything on my axes (fig.gca()
returns the current axes), and since the limits have never been set, they defaults to an x and y range from 0 to 1.
Here"s a continuation of the example, showing how units matter:
circle1 = plt.Circle((0, 0), 2, color="r")
# now make a circle with no fill, which is good for hi-lighting key results
circle2 = plt.Circle((5, 5), 0.5, color="b", fill=False)
circle3 = plt.Circle((10, 10), 2, color="g", clip_on=False)
ax = plt.gca()
ax.cla() # clear things for fresh plot
# change default range so that new circles will work
ax.set_xlim((0, 10))
ax.set_ylim((0, 10))
# some data
ax.plot(range(11), "o", color="black")
# key data point that we are encircling
ax.plot((5), (5), "o", color="y")
ax.add_patch(circle1)
ax.add_patch(circle2)
ax.add_patch(circle3)
fig.savefig("plotcircles2.png")
which results in:
You can see how I set the fill of the 2nd circle to False
, which is useful for encircling key results (like my yellow data point).