Polar Matplotlib图中的箭头 [英] Arrows in Polar Matplotlib Plot

查看:60
本文介绍了Polar Matplotlib图中的箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制串联 R-L-C 电路中电阻器、电容器和电感器两端的电压相量.我已经完成了所有的计算,我可以用普通的 ax.plot(theta,r,....) 得到一个不错的图.

我想使相量矢量看起来像箭头.我一直在尝试使用 ax.arrow(0,0,theta,magnitude) 但它看起来仍然像一行.我编写的代码的要点在这里:

我尝试按照我在

当我在计算机上运行他们的代码时,我会得到

我在 Xubuntu 14.04 上运行 matplotlib 1.3.1.我确实看到我使用的示例是在2009年使用matplotlib 0.99.

任何帮助将不胜感激.

解决方案

箭头尺寸太大,这:

  import matplotlib将numpy导入为np导入matplotlib.pyplot作为plt打印matplotlib.__version__ =",matplotlib.__version__打印 "matplotlib.get_backend() = ", matplotlib.get_backend()# 雷达绿色,实心网格线plt.rc('grid', color='#316931', linewidth=1, linestyle='-')plt.rc('xtick',标签大小= 15)plt.rc('ytick', labelsize=15)# 强制方形图形和方形轴看起来更适合极地,IMO宽度,高度 = matplotlib.rcParams['figure.figsize']大小 = 分钟(宽度,高度)# 画一个正方形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)θ= 2 * np.pi * rax.plot(theta,r,color ='#ee8d18',lw = 3)ax.set_rmax(2.0)plt.grid(真)ax.set_title(很高兴!",fontsize = 20)#这是我添加的行:arr1 = plt.arrow(0, 0.5, 0, 1, alpha = 0.5, width = 0.015,edgecolor ='黑色',facecolor ='绿色',lw = 2,zorder = 5)# 45 度的箭头arr2 = plt.arrow(45/180. * np.pi,0.5,0,1,alpha = 0.5,width = 0.015,edgecolor ='黑色',facecolor ='绿色',lw = 2,zorder = 5)plt.show()

产生:

更好?:)

I am trying to plot the phasors of the voltage across the resistor, capacitor, and inductor in an series R-L-C circuit. I have done all of the calculations and I can get a decent plot with just the normal 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. The gist to the code that I have written is here : 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. I do see that the example I am using was using matplotlib 0.99 in 2009.

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? :)

这篇关于Polar Matplotlib图中的箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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