setp函数--Matplotlib

函数功能:
Set a property on an artist object.
设置元素属性
函数语法:
setp(obj, *args, **kwargs)

函数参数:
obj: 要设置的对象

  1. matplotlib supports the use of setp() (“set property”) and getp() to set and get object properties, as well as to do introspection on the object.
    matplotlib 支持使用setp()函数设置属性,使用getp()函数获取查看属性,以及进行自查。

例如要将线条风格设置为虚线,可以:

line, = plot([1,2,3])
setp(line, linestyle='--')
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)

line1,=plt.plot(x,y)

plt.setp(line1,ls='--')

plt.show()

在这里插入图片描述

  1. If you want to know the valid types of arguments, you can provide the name of the property you want to set without a value:
    如果您想知道参数有效的类型(可取的值),则可以提供要设置的属性名称,但不带值。
setp(line, 'linestyle')

例如:获取线条风格的取值有哪些

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)

line,=plt.plot(x,y)

plt.setp(line,'linestyle')

运行结果
在这里插入图片描述
3. If you want to see all the properties that can be set, and their possible values, you can do:
如果你想要查看所有可以设置的属性和属性的取值,可以:

setp(line)
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-2*np.pi, 2 * np.pi, 200)
y = np.sin(x)

line1,=plt.plot(x,y)

plt.setp(line1)

运行结果如下:

  agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
  alpha: float or None
  animated: bool
  antialiased or aa: bool
  clip_box: `.Bbox`
  clip_on: bool
  clip_path: Patch or (Path, Transform) or None
  color or c: color
  contains: unknown
  dash_capstyle: {'butt', 'round', 'projecting'}
  dash_joinstyle: {'miter', 'round', 'bevel'}
  dashes: sequence of floats (on/off ink in points) or (None, None)
  data: (2, N) array or two 1D arrays
  drawstyle or ds: {'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
  figure: `.Figure`
  fillstyle: {'full', 'left', 'right', 'bottom', 'top', 'none'}
  gid: str
  in_layout: bool
  label: object
  linestyle or ls: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
  linewidth or lw: float
  marker: marker style string, `~.path.Path` or `~.markers.MarkerStyle`
  markeredgecolor or mec: color
  markeredgewidth or mew: float
  markerfacecolor or mfc: color
  markerfacecoloralt or mfcalt: color
  markersize or ms: float
  markevery: None or int or (int, int) or slice or List[int] or float or (float, float) or List[bool]
  path_effects: `.AbstractPathEffect`
  picker: unknown
  pickradius: float
  rasterized: bool or None
  sketch_params: (scale: float, length: float, randomness: float)
  snap: bool or None
  solid_capstyle: {'butt', 'round', 'projecting'}
  solid_joinstyle: {'miter', 'round', 'bevel'}
  transform: `matplotlib.transforms.Transform`
  url: str
  visible: bool
  xdata: 1D array
  ydata: 1D array
  zorder: float

Process finished with exit code 0

官方文档: setp函数

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
matplotlib.pyplot是一个Python的绘图库,它包含了一系列类似于matlab的画图函数。这些函数可以作用于当前图形(figure)的当前坐标系(axes)。\[1\]下面是一些使用matplotlib.pyplot的示例代码: 示例1: ```python import matplotlib.pyplot as plt y = \[0,1,4,9,16\] line = plt.plot(y)\[0\] line.set_color('r') line.set_linestyle('-.') plt.show() ``` 示例2: ```python import matplotlib.pyplot as plt y = \[0,1,4,9,16\] line = plt.plot(y)\[0\] line.set(color='r',ls='-.') plt.show() ``` 示例3: ```python import matplotlib.pyplot as plt y = \[0,1,4,9,16\] line = plt.plot(y)\[0\] plt.setp(line,color='r',ls='-.') plt.show() ``` 这三种方法得到的图形是一样的。\[2\]另外,你还可以使用numpy库来生成数据,并使用matplotlib.pyplot来绘制图形。例如,下面的代码绘制了正弦函数和余弦函数的图形: ```python import numpy as np import matplotlib.pyplot as plt x = np.arange(-6,6,0.1) y1 = np.sin(x) y2 = np.cos(x) plt.plot(x,y1) plt.plot(x,y2) plt.show() ``` 这段代码会生成一个包含正弦函数和余弦函数的图形。\[3\] #### 引用[.reference_title] - *1* [数据分析之Matplotlib(二)折线图(plot)](https://blog.csdn.net/qq_42642945/article/details/88320171)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [matplotlib入门 ----plot()函数](https://blog.csdn.net/ckk727/article/details/100180346)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值