本文整理汇总了Python中matplotlib.collections.LineCollection.set_norm方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_norm方法的具体用法?Python LineCollection.set_norm怎么用?Python LineCollection.set_norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_norm方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __plot_all
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def __plot_all(self):
total = len(self.data)
count = 0.0
for timeStamp in self.data:
if len(self.data[timeStamp]) < 2:
self.parent.threadPlot = None
return None, None
if self.fade:
alpha = (total - count) / total
else:
alpha = 1
data = self.data[timeStamp].items()
peakF, peakL = self.extent.get_peak_fl()
segments, levels = self.__create_segments(data)
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.__get_norm(self.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
lc.set_alpha(alpha)
self.axes.add_collection(lc)
count += 1
return peakF, peakL
示例2: __init__
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
class Visualize:
def __init__(self, v, t, e, fig, win, axesLimit=[-3,3.5,-2,2]):
self.e = e.copy()
self.p = [Polygon(v[ti]) for ti in t]
self.p = PatchCollection(self.p, edgecolors='none')
self.l = LineCollection(v[e[:,:2]])
win = win or fig.canvas.manager.window
if fig is None: fig = gcf()
fig.clf()
ax = fig.add_axes([0.02,0.02,.98,.98])
ax.axis('scaled')
ax.axis(axesLimit)
ax.set_autoscale_on(False)
self.axis, self.fig, self.win = ax, fig, win
ax.add_collection(self.p)
ax.add_collection(self.l)
# ax.add_collection(self.l1)
# ax.add_collection(self.l2)
def update(self, title, phi):
norm = Normalize(phi.min(), phi.max())
self.p.set_norm(norm)
self.l.set_norm(norm)
self.p.set_array(phi)
self.l.set_array(phi[self.e[:,2:]].mean(1))
if not self.__dict__.has_key('colorbar'):
self.colorbar = self.fig.colorbar(self.p)
self.win.set_title(title)
#self.fig.canvas.set_window_title(title)
self.fig.canvas.draw()
示例3: __plot_all
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def __plot_all(self, spectrum):
total = len(spectrum)
count = 0.0
for timeStamp in spectrum:
if self.settings.fadeScans:
alpha = (total - count) / total
else:
alpha = 1
data = spectrum[timeStamp].items()
peakF, peakL = self.extent.get_peak_fl()
segments, levels = self.__create_segments(data)
if segments is not None:
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.__get_norm(self.settings.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
lc.set_alpha(alpha)
self.axes.add_collection(lc)
count += 1
return peakF, peakL
示例4: __plot_single
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def __plot_single(self, points):
data = points.items()
peakF, peakL = max(data, key=lambda item: item[1])
segments, levels = self.__create_segments(data)
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.__get_norm(self.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
self.axes.add_collection(lc)
return peakF, peakL
示例5: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
#.........这里部分代码省略.........
subplot spcification
ax : Optional[ ]
Existing main axes
aax : Optional[ ]
Existing auxialary axes
zorder : Optional[int]
Returns
-------
ax : matplotlib.axes
object containing formatting
aax : matplotlib.axes
object containing data
cbax : matplotlib.axes
object containing colorbar
Example
-------
# Show ionospheric scatter
import datetime as dt
from models import raydarn
sTime = dt.datetime(2012, 11, 18, 5)
rto = raydarn.RtRun(sTime, rCode='bks', beam=12)
rto.readRays() # read rays into memory
ax, aax, cbax = rto.rays.plot(sTime, title=True)
rto.readScatter() # read scatter into memory
rto.scatter.plot(sTime, ax=ax, aax=aax)
ax.grid()
written by Sebastien, 2013-04
"""
from davitpy.utils import plotUtils
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt
import numpy as np
# Set up axes
if not ax and not aax:
ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect,
maxground=maxground, maxalt=maxalt)
else:
ax = ax
aax = aax
if hasattr(ax, 'beam'):
beam = ax.beam
# make sure that the required time and beam are present
assert (time in self.isc.keys() or time in self.gsc.keys()), logging.error('Unkown time %s' % time)
if beam:
assert (beam in self.isc[time].keys()), logging.error('Unkown beam %s' % beam)
else:
beam = self.isc[time].keys()[0]
if gscat and time in self.gsc.keys():
for ir, (el, rays) in enumerate( sorted(self.gsc[time][beam].items()) ):
if len(rays['r']) == 0: continue
_ = aax.scatter(rays['th'], ax.Re*np.ones(rays['th'].shape),
color='0', zorder=zorder)
if iscat and time in self.isc.keys():
if weighted:
wmin = np.min( [ r['w'].min() for r in self.isc[time][beam].values() if r['nstp'] > 0] )
wmax = np.max( [ r['w'].max() for r in self.isc[time][beam].values() if r['nstp'] > 0] )
for ir, (el, rays) in enumerate( sorted(self.isc[time][beam].items()) ):
if rays['nstp'] == 0: continue
t = rays['th']
r = rays['r']*1e-3
spts = np.array([t, r]).T.reshape(-1, 1, 2)
h = rays['h']*1e-3
rel = np.radians( rays['rel'] )
r = np.sqrt( r**2 + h**2 + 2*r*h*np.sin( rel ) )
t = t + np.arcsin( h/r * np.cos( rel ) )
epts = np.array([t, r]).T.reshape(-1, 1, 2)
segments = np.concatenate([spts, epts], axis=1)
lcol = LineCollection( segments, zorder=zorder )
if weighted:
_ = lcol.set_cmap( cmap )
_ = lcol.set_norm( plt.Normalize(0, 1) )
_ = lcol.set_array( ( rays['w'] - wmin ) / wmax )
else:
_ = lcol.set_color('0')
_ = aax.add_collection( lcol )
# Plot title with date ut time and local time
if title:
stitle = _getTitle(time, beam, self.header, None)
ax.set_title( stitle )
# If weighted, plot ionospheric scatter with colormap
if weighted:
# Add a colorbar
cbax = plotUtils.addColorbar(lcol, ax)
_ = cbax.set_ylabel("Ionospheric Scatter")
else: cbax = None
ax.beam = beam
return ax, aax, cbax
示例6: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def plot(self, time, beam=None, maxground=2000, maxalt=500, step=1,
showrefract=False, nr_cmap='jet_r', nr_lim=[0.8, 1.],
raycolor='0.4',
fig=None, rect=111):
"""Plot ray paths
**Args**:
* **time** (datetime.datetime): time of rays
* [**beam**]: beam number
* [**maxground**]: maximum ground range [km]
* [**maxalt**]: highest altitude limit [km]
* [**step**]: step between each plotted ray (in number of ray steps)
* [**showrefract**]: show refractive index along ray paths (supersedes raycolor)
* [**nr_cmap**]: color map name for refractive index coloring
* [**nr_lim**]: refractive index plotting limits
* [**raycolor**]: color of ray paths
* [**rect**]: subplot spcification
* [**fig**]: A pylab.figure object (default to gcf)
**Returns**:
* **ax**: matplotlib.axes object containing formatting
* **aax**: matplotlib.axes object containing data
* **cbax**: matplotlib.axes object containing colorbar
**Example**:
::
# Show ray paths with colored refractive index along path
import datetime as dt
from models import raydarn
sTime = dt.datetime(2012, 11, 18, 5)
rto = raydarn.rtRun(sTime, rCode='bks', beam=12)
rto.readRays() # read rays into memory
ax, aax, cbax = rto.rays.plot(sTime, step=2, showrefract=True, nr_lim=[.85,1])
ax.grid()
written by Sebastien, 2013-04
"""
from utils import plotUtils
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt
import numpy as np
ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect,
maxground=maxground, maxalt=maxalt)
# make sure that the required time and beam are present
assert (time in self.paths.keys()), 'Unkown time %s' % time
if beam:
assert (beam in self.paths[time].keys()), 'Unkown beam %s' % beam
else:
beam = self.paths[time].keys()[0]
for ir, (el, rays) in enumerate( sorted(self.paths[time][beam].items()) ):
if not ir % step:
if not showrefract:
aax.plot(rays['th'], rays['r']*1e-3, c=raycolor, zorder=2)
else:
points = np.array([rays['th'], rays['r']*1e-3]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lcol = LineCollection( segments )
lcol.set_cmap( nr_cmap )
lcol.set_norm( plt.Normalize(*nr_lim) )
lcol.set_array( rays['nr'] )
aax.add_collection( lcol )
# Add a colorbar when plotting refractive index
if showrefract:
from mpl_toolkits.axes_grid1 import SubplotDivider, LocatableAxes, Size
fig1 = ax.get_figure()
divider = SubplotDivider(fig1, *ax.get_geometry(), aspect=True)
# axes for colorbar
cbax = LocatableAxes(fig1, divider.get_position())
h = [Size.AxesX(ax), # main axes
Size.Fixed(0.1), # padding
Size.Fixed(0.2)] # colorbar
v = [Size.AxesY(ax)]
divider.set_horizontal(h)
divider.set_vertical(v)
ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
cbax.set_axes_locator(divider.new_locator(nx=2, ny=0))
fig1.add_axes(cbax)
cbax.axis["left"].toggle(all=False)
cbax.axis["top"].toggle(all=False)
cbax.axis["bottom"].toggle(all=False)
cbax.axis["right"].toggle(ticklabels=True, label=True)
plt.colorbar(lcol, cax=cbax)
cbax.set_ylabel("refractive index")
return ax, aax, cbax
示例7: run
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def run(self):
if self.data is None:
self.parent.threadPlot = None
return
peakF = None
peakL = None
total = len(self.data)
if total > 0:
self.parent.clear_plots()
lc = None
if self.average:
avg = OrderedDict()
count = len(self.data)
for timeStamp in self.data:
if len(self.data[timeStamp]) < 2:
return
for x, y in self.data[timeStamp].items():
if x in avg:
avg[x] = (avg[x] + y) / 2
else:
avg[x] = y
data = avg.items()
peakF, peakL = max(data, key=lambda item: item[1])
segments, levels = self.create_segments(data)
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.get_norm(self.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
self.axes.add_collection(lc)
self.parent.lc = lc
else:
count = 0.0
for timeStamp in self.data:
if len(self.data[timeStamp]) < 2:
self.parent.threadPlot = None
return
if self.fade:
alpha = (total - count) / total
else:
alpha = 1
data = self.data[timeStamp].items()
peakF, peakL = self.extent.get_peak_fl()
segments, levels = self.create_segments(data)
lc = LineCollection(segments)
lc.set_array(numpy.array(levels))
lc.set_norm(self.get_norm(self.autoL, self.extent))
lc.set_cmap(self.colourMap)
lc.set_linewidth(self.lineWidth)
lc.set_gid('plot')
lc.set_alpha(alpha)
self.axes.add_collection(lc)
count += 1
if self.annotate:
self.annotate_plot(peakF, peakL)
if total > 0:
self.parent.scale_plot()
self.parent.redraw_plot()
self.parent.threadPlot = None
示例8: plot
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_norm [as 别名]
def plot(self, time, beam=None,
maxground=2000, maxalt=500, step=1,
showrefract=False, nr_cmap='jet_r', nr_lim=[0.8, 1.],
raycolor='0.3', title=False, zorder=2, alpha=1,
fig=None, rect=111, ax=None, aax=None):
"""Plot ray paths
**Args**:
* **time** (datetime.datetime): time of rays
* [**beam**]: beam number
* [**maxground**]: maximum ground range [km]
* [**maxalt**]: highest altitude limit [km]
* [**step**]: step between each plotted ray (in number of ray steps)
* [**showrefract**]: show refractive index along ray paths (supersedes raycolor)
* [**nr_cmap**]: color map name for refractive index coloring
* [**nr_lim**]: refractive index plotting limits
* [**raycolor**]: color of ray paths
* [**rect**]: subplot spcification
* [**fig**]: A pylab.figure object (default to gcf)
* [**title**]: Show default title
* [**ax**]: Existing main axes
* [**aax**]: Existing auxialary axes
**Returns**:
* **ax**: matplotlib.axes object containing formatting
* **aax**: matplotlib.axes object containing data
* **cbax**: matplotlib.axes object containing colorbar
**Example**:
::
# Show ray paths with colored refractive index along path
import datetime as dt
from models import raydarn
sTime = dt.datetime(2012, 11, 18, 5)
rto = raydarn.RtRun(sTime, rCode='bks', beam=12, title=True)
rto.readRays() # read rays into memory
ax, aax, cbax = rto.rays.plot(sTime, step=10, showrefract=True, nr_lim=[.85,1])
ax.grid()
written by Sebastien, 2013-04
"""
from utils import plotUtils
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt
import numpy as np
from types import MethodType
# Set up axes
if not ax and not aax:
ax, aax = plotUtils.curvedEarthAxes(fig=fig, rect=rect,
maxground=maxground, maxalt=maxalt)
else:
ax = ax
aax = aax
if hasattr(ax, 'time'):
time = ax.time
if hasattr(ax, 'beam'):
beam = ax.beam
# make sure that the required time and beam are present
assert (time in self.paths.keys()), 'Unkown time %s' % time
if beam:
assert (beam in self.paths[time].keys()), 'Unkown beam %s' % beam
else:
beam = self.paths[time].keys()[0]
for ir, (el, rays) in enumerate( sorted(self.paths[time][beam].items()) ):
if not ir % step:
if not showrefract:
aax.plot(rays['th'], rays['r']*1e-3, c=raycolor,
zorder=zorder, alpha=alpha)
else:
points = np.array([rays['th'], rays['r']*1e-3]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lcol = LineCollection( segments, zorder=zorder, alpha=alpha)
_ = lcol.set_cmap( nr_cmap )
_ = lcol.set_norm( plt.Normalize(*nr_lim) )
_ = lcol.set_array( rays['nr'] )
_ = aax.add_collection( lcol )
# Plot title with date ut time and local time
if title:
stitle = _getTitle(time, beam, self.header, self.name)
ax.set_title( stitle )
# Add a colorbar when plotting refractive index
if showrefract:
cbax = plotUtils.addColorbar(lcol, ax)
_ = cbax.set_ylabel("refractive index")
else: cbax = None
# Declare a new method to show range markers
# This method is only available after rays have been plotted
# This ensures that the markers match the plotted rays
def showRange(self, markers=None,
color='.8', s=2, zorder=3,
**kwargs):
"""Plot ray paths
**Args**:
* [**markers**]: range markers. Defaults to every 250 km
#.........这里部分代码省略.........