Skip to content Skip to sidebar Skip to footer

Python/mathplotlib Plot Equivalent Of R's Symbol Plot?

Is there a python equivalent of this? symbols   package:graphics   R Documentation Draw Symbols (Circles, Squares, Stars, Thermometers, Boxplots) Description: This fu

Solution 1:

You can plot a circle of specific size at a given point using

import matplotlib.pyplotas plt
circle=plt.Circle((0,0),.2,color='r')
plt.add_artist(circle)

The format is Circle(x, y), radius) where x and y are the position of the center in the plot. See this question for more detail and explanation.

A rectangle (or square) of given size with

import matplotlib.pyplotas plt
import matplotlib.patchesas patches

rect = patches.Rectangle((50,100),40,30,facecolor='none')
plt.gca().add_patch(rect)

The format is Rectangle((x, y), w, h) where x and y are the coordinates in the plot of the top-left corner, w is the width and h is the height.

You can make an arbitrary polygon (i.e. a star) using

import matplotlib.pyplotas plt
import matplotlib.patchesas patches

poly = patches.Polygon(points, facecolor='None')
plt.gca().add_patch(poly)

Where points is an numpy array of shape Nx2 (where N is the number of points) of the vertices of the polygon. More information (including keyword arguments) is available on the matplotlib docs for polygon and rectangle. I you just want those symbols as markers you can simply do

plt.scatter(x, y, marker='*')

Where x and y are arrays or array-like of the coordinates at which you want the markers. The marker used can be specified according to the matplotlib markers docs. You can also draw a custom marker by supplying a path to draw, similar to how the polygon is drawn.

Post a Comment for "Python/mathplotlib Plot Equivalent Of R's Symbol Plot?"