python/mathplotlib 图相当于 R 的符号图? [英] python/mathplotlib plot equivalent of R's symbol plot?

查看:75
本文介绍了python/mathplotlib 图相当于 R 的符号图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有类似的python吗?

Is there a python equivalent of this?

符号  包:图形  R 文档

symbols   package:graphics   R Documentation

绘制符号(圆形、正方形、星星、温度计、箱线图)

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

说明:

此函数在图上绘制符号.六个符号之一;圆形正方形矩形星星温度计boxplots,可以在一组指定的 x 和 y 处绘制坐标.符号的特定方面,例如相对尺寸,可通过附加参数定制.

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.

推荐答案

您可以使用

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

格式为 Circle(x, y), radius) 其中 xy 是图中中心的位置.有关更多详细信息和解释,请参阅这个问题.

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)

格式为 Rectangle((x, y), w, h) 其中 xy 是图中的坐标左上角,w 是宽度,h 是高度.

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.

您可以使用

import matplotlib.pyplot as plt
import matplotlib.patches as patches

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

其中 points 是形状为 Nx2numpy 数组(其中 N 是点的数量)多边形的顶点.有关 polygon矩形.我只是想要这些符号作为标记,你可以简单地做

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='*')

其中 xy 是您想要标记的坐标的数组或类似数组.可以根据 matplotlib markers 文档指定使用的标记.您还可以通过提供要绘制的 path 来绘制自定义标记,类似于绘制 polygon 的方式.

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.

这篇关于python/mathplotlib 图相当于 R 的符号图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆