简体   繁体   English

极地Matplotlib图中的箭头

[英]Arrows in Polar Matplotlib Plot

I am trying to plot the phasors of the voltage across the resistor, capacitor, and inductor in an series RLC circuit. 我试图绘制一系列RLC电路中电阻,电容和电感两端电压的相量。 I have done all of the calculations and I can get a decent plot with just the normal ax.plot(theta,r,....) . 我已经完成了所有的计算,我可以用正常的ax.plot(theta,r,....)得到一个不错的情节。

I would like to make the phasor vectors look like arrows. 我想让相量矢量看起来像箭头。 I have been trying to use ax.arrow(0,0,theta,magnitude) but it looks like a line still. 我一直在尝试使用ax.arrow(0,0,theta,magnitude)但它看起来像一条线。 The gist to the code that I have written is here : GIST 我写的代码的要点是: GIST

My image that I create is 我创建的图像是

I tried to follow the example that I found on this list because it is very similar to what I want to accomplish, it produces the following image: 我试着按照我在这个列表中找到的例子,因为它与我想要完成的非常相似,它产生了以下图像:

When I run their code on my computer I get 当我在我的电脑上运行他们的代码时,我得到了

I am on Xubuntu 14.04 and running matplotlib 1.3.1. 我在Xubuntu 14.04上运行matplotlib 1.3.1。 I do see that the example I am using was using matplotlib 0.99 in 2009. 我确实看到我使用的示例是在2009年使用matplotlib 0.99。

Any help would be much appreciated. 任何帮助将非常感激。

Arrow sizes were too big, this: 箭头尺寸太大了,这个:

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

print "matplotlib.__version__   = ", matplotlib.__version__
print "matplotlib.get_backend() = ", matplotlib.get_backend()


# radar green, solid grid lines
plt.rc('grid', color='#316931', linewidth=1, linestyle='-')
plt.rc('xtick', labelsize=15)
plt.rc('ytick', labelsize=15)

# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = plt.figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')

r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.0)
plt.grid(True)

ax.set_title("And there was much rejoicing!", fontsize=20)
#This is the line I added:
arr1 = plt.arrow(0, 0.5, 0, 1, alpha = 0.5, width = 0.015,
                 edgecolor = 'black', facecolor = 'green', lw = 2, zorder = 5)

# arrow at 45 degree
arr2 = plt.arrow(45/180.*np.pi, 0.5, 0, 1, alpha = 0.5, width = 0.015,
                 edgecolor = 'black', facecolor = 'green', lw = 2, zorder = 5)

plt.show()

Produces: 生产:

在此输入图像描述

Better? 更好? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM