未显示 Quiverkey 参考箭头
Quiverkey reference arrow is not being displayed
我的 quiverkey 中缺少参考箭头,我不知道为什么。
有人能看出我做错了什么吗?我最初没有使用 gridspec,但我需要这样我的数字才能正确缩放。当我不使用 gridspec 时,会显示参考箭头,但现在不再显示了。为什么 gridspec 会导致我丢失 quiverkey 的参考箭头?
Matplotlib 版本:1.4.3
Python 版本:2.7.10
注:棒图函数取自here.
import matplotlib.pyplot as plot
import matplotlib as mpl
from mpl_toolkits.basemap import Basemap
import numpy as np
from datetime import datetime, timedelta
import matplotlib.gridspec as gridspec
from matplotlib.dates import date2num
def stick_plot(time, u, v, **kw):
width = kw.pop('width', 0.002)
headwidth = kw.pop('headwidth', 0)
headlength = kw.pop('headlength', 0)
headaxislength = kw.pop('headaxislength', 0)
angles = kw.pop('angles', 'uv')
ax = kw.pop('ax', None)
if angles != 'uv':
raise AssertionError("Stickplot angles must be 'uv' so that"
"if *U*==*V* the angle of the arrow on"
"the plot is 45 degrees CCW from the *x*-axis.")
if not ax:
fig, ax = plot.subplots()
q = ax.quiver(date2num(time), [[0]*len(time)], u, v,
angles='uv', width=width, headwidth=headwidth,
headlength=headlength, headaxislength=headaxislength,
**kw)
ax.axes.get_yaxis().set_visible(False)
ax.xaxis_date()
return q
x = np.arange(100, 110, 0.1)
start = datetime.now()
time = [start + timedelta(days=n) for n in range(len(x))]
u, v = np.sin(x), np.cos(x)
gs = gridspec.GridSpec(1,3, width_ratios = [5,1,3], height_ratios = [2,1])
fig = plot.figure(figsize=(11,8))
ax1 = plot.subplot(gs[:, :-1])
ax2 = plot.subplot(gs[:, -1])
map1 = Basemap(ax = ax1)
map1.drawcoastlines()
q = stick_plot(time, u, v, ax = ax2)
ref = 1
qk = plot.quiverkey(q, 0.3, 0.85, ref,
"%s N m$^{-2}$" % ref,
labelpos='N', coordinates='axes')
_ = plot.xticks(rotation=30)
plot.show()
图片:
我有类似的问题。在 quiver()
的调用中明确设置 linewidth
关键字为我解决了这个问题。
估计是plot坐标系和quiverkey坐标系冲突导致的问题。尝试输出到图形文件,如:
plt.savefig("xxx.jpg")
我的 quiverkey 中缺少参考箭头,我不知道为什么。
有人能看出我做错了什么吗?我最初没有使用 gridspec,但我需要这样我的数字才能正确缩放。当我不使用 gridspec 时,会显示参考箭头,但现在不再显示了。为什么 gridspec 会导致我丢失 quiverkey 的参考箭头?
Matplotlib 版本:1.4.3
Python 版本:2.7.10
注:棒图函数取自here.
import matplotlib.pyplot as plot
import matplotlib as mpl
from mpl_toolkits.basemap import Basemap
import numpy as np
from datetime import datetime, timedelta
import matplotlib.gridspec as gridspec
from matplotlib.dates import date2num
def stick_plot(time, u, v, **kw):
width = kw.pop('width', 0.002)
headwidth = kw.pop('headwidth', 0)
headlength = kw.pop('headlength', 0)
headaxislength = kw.pop('headaxislength', 0)
angles = kw.pop('angles', 'uv')
ax = kw.pop('ax', None)
if angles != 'uv':
raise AssertionError("Stickplot angles must be 'uv' so that"
"if *U*==*V* the angle of the arrow on"
"the plot is 45 degrees CCW from the *x*-axis.")
if not ax:
fig, ax = plot.subplots()
q = ax.quiver(date2num(time), [[0]*len(time)], u, v,
angles='uv', width=width, headwidth=headwidth,
headlength=headlength, headaxislength=headaxislength,
**kw)
ax.axes.get_yaxis().set_visible(False)
ax.xaxis_date()
return q
x = np.arange(100, 110, 0.1)
start = datetime.now()
time = [start + timedelta(days=n) for n in range(len(x))]
u, v = np.sin(x), np.cos(x)
gs = gridspec.GridSpec(1,3, width_ratios = [5,1,3], height_ratios = [2,1])
fig = plot.figure(figsize=(11,8))
ax1 = plot.subplot(gs[:, :-1])
ax2 = plot.subplot(gs[:, -1])
map1 = Basemap(ax = ax1)
map1.drawcoastlines()
q = stick_plot(time, u, v, ax = ax2)
ref = 1
qk = plot.quiverkey(q, 0.3, 0.85, ref,
"%s N m$^{-2}$" % ref,
labelpos='N', coordinates='axes')
_ = plot.xticks(rotation=30)
plot.show()
图片:
我有类似的问题。在 quiver()
的调用中明确设置 linewidth
关键字为我解决了这个问题。
估计是plot坐标系和quiverkey坐标系冲突导致的问题。尝试输出到图形文件,如:
plt.savefig("xxx.jpg")