def plot_fewer_markers( x, ax, marker_npnt, line_npnt, style, **kwargs ): """Same line, different number of markers. @param ax: axes object handle @param x: abscissa vector @param marker_npnt: # markers @param line_npnt: # points used for line @param style: line and marker style = plot style string, e.g., 'ro--' | cell array {graph_color, line_style, marker_style}, e.g., {'b', '--', 'o'}, or {[0,0,1], '--', 'o'} note: the 2nd option allows for RGB color specification. """ # input if nargin < 3: style = '' # defaults by parse_plot_style if nargin < 4: marker_npnt = 10 if nargin < 5: line_npnt = 100 # cell with RGB color specs ? if iscell(style): graph_color = style[0] line_style = style[1] marker_style = style[2] else: # or string style ? graph_color, marker_style, \ line_style = parse_plot_style(style) # nargout=3 # # plot c = takehold(ax, 'on') # marker of 1st pnt for legend to get correct style plot(ax, x[:, 0], 'Color', graph_color, 'LineStyle', line_style, 'Marker', marker_style) # line plot_subsample(ax, x, line_npnt, 'Color', graph_color, 'LineStyle', line_style, 'Marker', 'none', 'HandleVisibility', 'off') # markers plot_subsample(ax, x, marker_npnt, 'Color', graph_color, 'LineStyle', 'none', 'Marker', marker_style, 'HandleVisibility', 'off') restorehold(ax, c)
def plot_subsample_arclength(x, n=100, ax, **kwargs): """Subsample wrt arclength metric & plot curve. @param ax: axes object handle where to plot @param x: point abscissas (as passed to plot) @param y: point ordinates (as passed to plot) @param n: number of points to keep > 0 @param kwargs: arguments passed to plot """ if not isscalar(n): error('n: # of sample, must be scalar.') # plot x = subsample(x, n, 2, 'arclength') plot(ax, x, varargin[:])
def test_plot_subsample_arclength(): """Visually compare plot, plot_subsample, plot_subsample_arclength. """ from math import exp cls t = 2 *np.pi /exp(range(10) ) x = np.array([cos(t), sin(t)]).reshape(1, -1) fig = figure ax = newax(fig, np.array([1, 3]).reshape(1, -1)) mhold(ax, 'on') plot(ax, x, 'ro-') plot_subsample(ax(2), x, 100, 'm--*') plot_subsample_arclength(ax(3), x, 100, 'bs') supertitle(fig, 'Comparison: plot subsampling methods') stitle = ['plot', 'plot\\_subsample', 'plot\\_subsample\\_arclength'] plotidy2(ax, '$x$', '$y$', stitle) axis(ax, 'image')
def example_plot_subsample(): """example using plot_subsample, plot2_subsample """ npnt = 1000 n_sample = 10 t = linspace(0, 4 * pi, npnt) fig = figure ax = newax(fig, np.array([1, 2]).reshape(1, -1)) mhold(ax, 'on') """2d example""" x = t y = sin(t) plt.plot(ax(1), x, y, 'b-') plot2_subsample(ax(1), x, y, n_sample, 'r--o') plotidy2(ax(1)) """3d example""" x = np.array([t, cos(t), sin(t)]).reshape(1, -1) plot(ax(2), x, 'b-') plot_subsample(ax(2), x, n_sample, 'r--o') plotidy(ax(2)) axis(ax(2), 'equal')