matplotlib之极坐标系的极角网格线(thetagrids)的显示刻度

2018/05/23 13:54
阅读数 2.7K

极坐标系的极角网格线(thetagrids)的显示刻度

 1 #!/usr/bin/env python3
 2 #-*- coding:utf-8 -*-
 3 ############################
 4 #File Name: polar.py
 5 #Author: frank
 6 #Mail: frank0903@aliyun.com
 7 #Created Time:2018-05-22 22:08:01
 8 ############################
 9 import matplotlib.pyplot as plt
10 import numpy as np
11 import matplotlib as mpl
12 
13 zhfont = mpl.font_manager.FontProperties(fname='/usr/share/fonts/truetype/wqy/wqy-microhei.ttc')
14 
15 ax = plt.subplot(111, polar=True)
16 
17 plt.figtext(0.52, 0.95, '默认labels为角度(degree)', ha='center', size=20,fontproperties=zhfont)
18 plt.thetagrids(np.linspace(0, 360, 6, endpoint=False))
19 plt.savefig('default_degrees.jpg')
20 
21 plt.figtext(0.52, 0.95, '指定labels', ha='center', size=20,fontproperties=zhfont)
22 plt.thetagrids(np.linspace(0, 360, 6, endpoint=False), ['a', 'b', 'c', 'd', 'e', 'f'])
23 plt.savefig('special_degrees.jpg')
24 
25 
26 plt.show()

 

 

matplotlib.pyplot.thetagrids(*args, **kwargs)
  Get or set the theta locations of the gridlines in a polar plot.

  get or set 极角轴显示刻度。

If no arguments are passed, return a tuple (lines, labels) where lines is an array of radial gridlines (Line2D instances) and labels is an array of tick labels (Text instances):
  lines, labels = thetagrids()
Otherwise the syntax is:
  lines, labels = thetagrids(angles, labels=None, fmt='%d', frac = 1.1)
  set the angles at which to place the theta grids (these gridlines are equal along the theta dimension).

angles is in degrees. 

angles 是角度值,不能是弧度值


labels, if not None, is a len(angles) list of strings of the labels to use at each angle. 

If labels is None, the labels will be fmt%angle.

如果labels不为空,那么极角网格线的显示刻度为labels。

如果labels为空,那么极角网格线的显示刻度为 角度值。


frac is the fraction of the polar axes radius at which to place the label (1 is the edge). e.g., 1.05 is outside the axes and 0.95 is inside the axes.

frac 设置 极角显示刻度 距离 极角轴的距离。例如,极径为1,frac=1.1,那么极角的刻度显示的位置 离 r=1的极角网格线 0.1长度。

Return value is a list of tuples (lines, labels):
  lines are Line2D instances
  labels are Text instances.

Note that on input, the labels argument is a list of strings, and on output it is a list of Text instances.

 

reference: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.thetagrids.html?highlight=thetagrids#matplotlib.pyplot.thetagrids

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部