matplotlib之设置极坐标的方向

 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 #2. 怎样设置极坐标的方向
14 plt.subplots_adjust(wspace=0.3)#控制两个subplot的间距,否则会有部分标签重叠
15 ax1 = plt.subplot(121, polar=True)
16 ax2 = plt.subplot(122, polar=True)
17 #print(dir(ax))
18 theta = np.arange(0, 2*np.pi, 0.1)
19 ax1.set_theta_direction(-1)
20 ax2.set_theta_direction('anticlockwise')
21 ax1.plot(theta, theta/6,'o--')
22 ax2.plot(theta, theta/6,'o--')
23 plt.savefig('theta_direction.jpg')
24 plt.show()

ax1 是顺时针方向的图

ax2 是逆时针方向的图

set_theta_direction(direction)

Set the direction in which theta increases.

clockwise, -1:
  Theta increases in the clockwise direction
counterclockwise, anticlockwise, 1:
  Theta increases in the counterclockwise direction

如果direction的值为1,表示逆时针方向,即默认theta增长方向;

如果direction的值为-1,表示顺时针方向。

同时direction也支持 ' clockwise','counterclockwise' ,'anticlockwise'

 

reference:https://matplotlib.org/api/projections_api.html?highlight=set_theta_direction#matplotlib.projections.polar.PolarAxes.set_theta_direction

posted @ 2018-05-23 12:59  suonikeyinsu  Views(1144)  Comments(0Edit  收藏  举报