2

Is there a python equivalent of this?

symbols   package:graphics   R Documentation

Draw Symbols (Circles, Squares, Stars, Thermometers, Boxplots)

Description:

This function draws symbols on a plot. One of six symbols; circles, squares, rectangles, stars, thermometers, and boxplots, can be plotted at a specified set of x and y coordinates. Specific aspects of the symbols, such as relative size, can be customized by additional parameters.

William Miller
  • 9,839
  • 3
  • 25
  • 46
Steve Dutky
  • 185
  • 11
  • If by python you mean using matplotlib, you can use a `scatter` plot. For boxplots use a `boxplot` though, and for thermometers... not sure how that would look like, but if there is a unicode symbol of it, it can be plotted. – ImportanceOfBeingErnest Feb 14 '19 at 21:34

1 Answers1

2

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

import matplotlib.pyplot as 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.pyplot as plt
import matplotlib.patches as 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.pyplot as plt
import matplotlib.patches as 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.

William Miller
  • 9,839
  • 3
  • 25
  • 46
  • Isn't the real question how to plot thermometers? – ImportanceOfBeingErnest Feb 14 '19 at 22:17
  • @ImportanceOfBeingErnest I don't see where the OP specified which symbol they are interested in. I included the `polygon` method and the note about custom markers as possible ways a 'thermometer' could be drawn, I'm not aware of any better way to do it - though I am sure it exists. – William Miller Feb 14 '19 at 22:27
  • The list of symbols they ask for is *circles, squares, rectangles, stars, thermometers, and boxplots*. Now there exist Stackoverflow answers for every item in that list, except for "thermomenter". Hence the only on-topic, non-duplicate question here would be how to plot thermometers, right? – ImportanceOfBeingErnest Feb 15 '19 at 20:29
  • I'm getting an error: `>>>> import matplotlib.pyplot as plt` `>>> import matplotlib.patches as patches` `>>> rect = patches.Rectangle((50,100),40,30,facecolor='none')` `>>> plt.add_patch(rect)` `Traceback (most recent call last):` ` File "", line 1, in ` `AttributeError: module 'matplotlib.pyplot' has no attribute 'add_patch'` – Steve Dutky Feb 16 '19 at 20:45
  • @SteveDutky Ah yes, you need an axis handle for `add_patch`, my bad. See the edited solution – William Miller Feb 17 '19 at 00:15
  • The real question about thermometers is now [here](https://stackoverflow.com/questions/54790467/how-to-plot-a-thermometer). – ImportanceOfBeingErnest Feb 20 '19 at 16:00