Skip to content

The simple.roseaxes Namespace

This contains the RoseAxes class and its utility functions.


simple.roseaxes.RoseAxes

RoseAxes(*args, **kwargs)

Bases: PolarAxes

A subclass of matplotlibs Polar Axes.

Rose plots can be created using the create_rose_plot function or by specifying the projection 'rose' using matplotlib functions.

Only custom and reimplemented methods are described here. See matplotlibs documentation for more methods. Note however, that these method might not behave as the reimplemented version below. For example the matplotlib methods will not take into account the xscale and yscale.

Note that some features, like axlines, might require an updated version of matplotlib to work.

Source code in simple/roseaxes.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def __init__(self, *args, **kwargs):
    self._xysegment = None
    self._yscale = 1
    self._xscale = 1
    self._rres = 720

    self._vrel, self._vmin, self._vmax = True, 0, 1
    self._norm = mpl.colors.Normalize(vmin=self._vmin, vmax=self._vmax)
    self._cmap = get_cmap('turbo')
    self._colorbar = None

    super().__init__(*args,
                     theta_offset=np.pi * 0.5, theta_direction=-1,
                     **kwargs)

    self.tick_params(axis='y', which='major', labelleft=False, labelright=False)
    self.tick_params(axis='y', which='minor')
    self.tick_params(axis='x', which='major', direction='out')
    self.margins(y=0.1)

name class-attribute instance-attribute

name = 'rose'

axmline

axmline(m, r=1, merr=None, eline=True, ecolor=None, elinestyle=':', elinewidth=None, ezorder=None, antipodal=None, **kwargs)

Draw a line along a slope.

Uses matplotlibs axvline method to draw the line(s).

Parameters:

  • m ((float, (float, float))) –

    Either a single slope or a tuple of x and y coordinates from which a slope will be calculated.

  • r ((float, (float, float)), default: 1 ) –

    If a single value is given a line will be drawn between the 0 and r. if a tuple of two values are given the line will be drawn between r[0] and r[1]. Note these are relative coordinates.

  • merr

    The uncertainty of the slope.

  • eline

    If True lines will also be drawn for the uncertainty of the slope.

  • ecolor

    The color used for the uncertainty lines.

  • elinestyle

    The line style used for the uncertainty lines.

  • elinewidth

    The line width used for the uncertainty lines.

  • ezorder

    The z order width used for the uncertainty lines.

  • antipodal

    Whether the antipodal data points will be drawn. By default, antipodal=True when m is a slope and antipodal=False when m is x,y coordinates.

  • **kwargs

    Additional keyword arguments passed to matplotlibs axvline method.

Source code in simple/roseaxes.py
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def axmline(self, m, r=1, merr=None, eline=True,
            ecolor=None, elinestyle=":", elinewidth=None, ezorder=None,
            antipodal=None, **kwargs):
    """
    Draw a line along a slope.

    Uses matplotlibs [axvline](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.axvline.html) method
    to draw the line(s).

    Args:
        m (float, (float, float)): Either a single slope or a tuple of *x* and *y*
            coordinates from which a slope will be calculated.
        r (float, (float, float)): If a single value is given a line will be drawn between the ``0`` and ``r``.
            if a tuple of two values are given the line will be drawn between ``r[0]`` and ``r[1]``. Note these
            are relative coordinates.
        merr (): The uncertainty of the slope.
        eline (): If ``True`` lines will also be drawn for the uncertainty of the slope.
        ecolor (): The color used for the uncertainty lines.
        elinestyle (): The line style used for the uncertainty lines.
        elinewidth (): The line width used for the uncertainty lines.
        ezorder (): The z order width used for the uncertainty lines.
        antipodal (): Whether the antipodal data points will be drawn. By default, ``antipodal=True`` when ``m`` is
            a slope and ``antipodal=False`` when ``m`` is *x,y* coordinates.
        **kwargs (): Additional keyword arguments passed to matplotlibs
            [axvline](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.axvline.html) method.
    """

    return self._mline(m, r, merr,
                       ecolor=ecolor, elinestyle=elinestyle, elinewidth=elinewidth,
                       ezorder=ezorder, ealpha=0, eline=eline, efill=False,
                       antipodal=antipodal, axline=True, **kwargs)

axrline

axrline(r, tmin=0, tmax=1, **kwargs)

Plot a line along a given radius.

Used matplotlibs axhline method to draw the line.

Parameters:

  • r

    The radius at which to draw the line.

  • tmin

    The starting angle of the line. In relative coordinates.

  • tmax

    The stopping angle of the line. In relative coordinates.

  • **kwargs

    Additional keyword arguments passed to matplotlibs axhline method.

Returns:

Source code in simple/roseaxes.py
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
def axrline(self, r, tmin=0, tmax=1, **kwargs):
    """
    Plot a line along a given radius.

    Used matplotlibs [axhline](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.axhline.html) method
    to draw the line.

    Args:
        r (): The radius at which to draw the line.
        tmin (): The starting angle of the line. In relative coordinates.
        tmax (): The stopping angle of the line. In relative coordinates.
        **kwargs (): Additional keyword arguments passed to matplotlibs
            [axhline](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.axhline.html) method.

    Returns:

    """
    return self.axhline(r, tmin, tmax, **kwargs)

clear

clear()

Clear the ax.

Source code in simple/roseaxes.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def clear(self):
    """
    Clear the ax.
    """
    super().clear()

    self._last_hist_r = 0
    self._bar_color_cycle = itertools.cycle(plt.rcParams['axes.prop_cycle'].by_key()['color'])

    # Grid stuff
    self.grid(True, axis='y', which='minor')
    self.grid(True, axis='y', which='major', color='black')
    self.grid(False, axis='x', which='minor')
    self.grid(True, axis='x', which='major')

    self.set_rlim(rmin=0)
    self.set_rticks([], minor=True)
    self.set_rticks([], minor=False)

    # Segment
    self.set_xysegment(self._xysegment)

get_rres

get_rres()

Return the resolution of lines drawn along the radius r.

Source code in simple/roseaxes.py
279
280
281
282
283
def get_rres(self):
    """
    Return the resolution of lines drawn along the radius ``r``.
    """
    return self._rres

get_xyscale

get_xyscale()

Return a tuple of the scale of the x and y dimensions of the rose diagram.

Source code in simple/roseaxes.py
219
220
221
222
223
def get_xyscale(self):
    """
    Return a tuple of the scale of the *x* and *y* dimensions of the rose diagram.
    """
    return (self._xscale, self._yscale)

merrorbar

merrorbar(m, r=1, merr=None, antipodal=None, **kwargs)

Plot data points with errorbars.

This is an adapted version of matplotlibs errorbar method.

Note it is currently not possible to add bar ends to the error bars.

Parameters:

  • m ((float, (float, float))) –

    Either a single array of floats representing a slope or a tuple of x and y coordinates from which a slope will be calculated.

  • r

    The radius at which the data points will be drawn.

  • merr

    The uncertainty of the slope.

  • antipodal

    Whether the antipodal data points will be drawn. By default, antipodal=True when m is a slope and antipodal=False when m is x,y coordinates.

  • **kwargs

    Additional keyword arguments passed to matplotlibs

  • [errorbar](https

    //matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.errorbar.html) method.

Source code in simple/roseaxes.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
def merrorbar(self, m, r=1, merr=None,
              antipodal=None,
              **kwargs):
    """
    Plot data points with errorbars.

    This is an adapted version of matplotlibs
    [errorbar](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.errorbar.html) method.

    **Note** it is currently not possible to add bar ends to the error bars.

    Args:
        m (float, (float, float)): Either a single array of floats representing a slope or a tuple of *x* and *y*
            coordinates from which a slope will be calculated.
        r (): The radius at which the data points will be drawn.
        merr (): The uncertainty of the slope.
        antipodal (): Whether the antipodal data points will be drawn. By default, ``antipodal=True`` when ``m`` is
            a slope and ``antipodal=False`` when ``m`` is *x,y* coordinates.
        **kwargs (): Additional keyword arguments passed to matplotlibs
        [errorbar](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.errorbar.html) method.
    """

    kwargs.setdefault('linestyle', '')
    kwargs.setdefault('marker', 'o')
    if type(m) is tuple and len(m) == 2:
        x, y = m
        if antipodal is None:
            antipodal = False
    else:
        x, y = 1, m
        if antipodal is None:
            antipodal = True

    x, y, r, merr = as1darray(x, y, r, merr)

    if merr is not None:
        # Makes errorbar show up in legend
        yerr = np.nan
    else:
        yerr = None

    kwargs['capsize'] = 0  # Because we cannot show these
    with warnings.catch_warnings():
        # Supresses warning that comes from having yerr as nan
        warnings.filterwarnings('ignore', message='All-NaN axis encountered', category=RuntimeWarning)
        data_line, caplines, barlinecols = self.errorbar(self._xy2rad(x, y), r, yerr=yerr, **kwargs)

    # print(len(barlinecols), barlinecols, barlinecols[0].get_colors(), barlinecols[0].get_linewidth())
    if merr is not None:
        colors = barlinecols[0].get_colors()
        if len(colors) == 1: colors = [colors[0]] * x.size

        linestyles = barlinecols[0].get_linestyles()
        if len(linestyles) == 1: linestyles = [linestyles[0]] * x.size

        linewidths = barlinecols[0].get_linewidths()
        if len(linewidths) == 1: linewidths = [linewidths[0]] * x.size

        zorder = barlinecols[0].get_zorder()

        for i in range(x.size):
            m = y[i] / x[i]
            self._rplot(self._xy2rad(x[i], (m + merr[i]) * x[i]), self._xy2rad(x[i], (m - merr[i]) * x[i]), r[i],
                        color=colors[i], linestyle=linestyles[i], linewidth=linewidths[i],
                        zorder=zorder, marker="")
    if antipodal:
        kwargs.pop('label', None)
        kwargs.pop('color', None)
        self.merrorbar((x * -1, y * -1), r, merr=merr, antipodal=False, color=data_line.get_color(), **kwargs)

mhist

mhist(m, r=None, weights=1, color=None, *, rheight=0.9, rescale=False, antipodal=None, bins=72, rtext=None, fill=True, outline=None, update_rticks=True, minor_rticks=2, rscale=True, cmap=False, **kwargs)

Create a histogram of the given slopes.

Parameters:

  • m ((float, (float, float))) –

    Either a single array of floats representing a slope or a tuple of x and y coordinates from which a slope will be calculated.

  • r

    The radius at which the histogram will be drawn. If 'None' it will be plotted 1 above the previous histogram, or at 1 if no histogram have been drawn.

  • color

    The color of the bars and the outline of the bars.

  • weights

    The weight assigned to each slope.

  • rheight

    The height of the histogram. If rscale=True this is the relative height of the histogram. Otherwise the cumulative height of all the bins will total to this value.

  • rescale

    If True all bin heights will be scaled relative to the heaviest bin. Otherwise, they are scaled relative to the sum of all bin weights or the range set by the colormap.

  • antipodal

    Whether the antipodal data points will be included in the histogram. By default,

  • bins

    The number of even sized bin in the histogram.

  • rtext

    A text label for the histogram in the plot. Created using the rtext method. Keyword arguments can be passed using the prefix rtext_.

  • fill (bool, default: True ) –

    If True the bars will be filled in.

  • outline

    If True the bar will be drawn with an outline. If False no outline will be drawn.

  • update_rticks

    If True the y axis ticks will be updated to include the radius of the histogram.

  • minor_rticks

    The number of minor ticks to draw between the major ticks.

  • rscale

    If True height of the individual bins will be scaled to their weight. Otherwise all bins will have the same height.

  • cmap

    If True, or the name of a colormap, the bars be coloured depending on their weight based on the colour map. If False all bars will have the same colour based on color.

  • **kwargs

    Additional keyword arguments. A description of accepted keywords is provided below.

Accepted keyword arguments

Direct keywords: - zorder the zorder of the bars and outline. The outline will be drawn on top of the bars. - label the label of the histogram. Note that the label is created as an emtpy artist to ensure consistensy with the label on 1-d histograms. - linestyle, linewidth the linestyle and linewidth of the outline and baseline. Can be set individually using the prefix outline_ and baseline_ respectively.

Prefixed keywords: - fill_<keyword>: Keywords passed to PolarAxes.fill_between when drawing the bars. - outline_<keyword>: Keywords passed to PolarAxes.plot when drawing the outline. - baseline_<keyword>: Keywords passed to PolarAxes.plot when drawing the baseline. - rtext_<keyword>: Keywords passed to PolarAxes.rtext when drawing the text label.

Source code in simple/roseaxes.py
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
def mhist(self, m, r=None, weights=1, color=None, *,
          rheight=0.9, rescale=False, antipodal=None, bins=72, rtext=None, fill=True, outline=None,
          update_rticks=True, minor_rticks=2, rscale=True, cmap=False, **kwargs):
    """
    Create a histogram of the given slopes.

    Args:
        m (float, (float, float)): Either a single array of floats representing a slope or a tuple of *x* and *y*
            coordinates from which a slope will be calculated.
        r (): The radius at which the histogram will be drawn. If 'None' it will be plotted ``1`` above the
            previous histogram, or at 1 if no histogram have been drawn.
        color (): The color of the bars and the outline of the bars.
        weights (): The weight assigned to each slope.
        rheight (): The height of the histogram. If ``rscale=True`` this is the relative height of the histogram.
            Otherwise the cumulative height of all the bins will total to this value.
        rescale (): If ``True`` all bin heights will be scaled relative to the heaviest bin. Otherwise, they are
            scaled relative to the sum of all bin weights or the range set by the colormap.
        antipodal (): Whether the antipodal data points will be included in the histogram. By default,
        ``antipodal=True`` when ``m`` is a slope and ``antipodal=False`` when ``m`` is *x,y* coordinates.
        bins (): The number of even sized bin in the histogram.
        rtext (): A text label for the histogram in the plot. Created using the ``rtext`` method. Keyword
            arguments can be passed using the prefix ``rtext_``.
        fill (bool): If ``True`` the bars will be filled in.
        outline (): If ``True`` the bar will be drawn with an outline. If ``False`` no outline will be drawn.
        update_rticks (): If ``True`` the y axis ticks will be updated to include the radius of the histogram.
        minor_rticks (): The number of minor ticks to draw between the major ticks.
        rscale (): If ``True`` height of the individual bins will be scaled to their weight. Otherwise all bins
            will have the same height.
        cmap (): If ``True``, or the name of a colormap, the bars be coloured depending on their weight based on
            the colour map. If `False` all bars will have the same colour based on *color*.
        **kwargs: Additional keyword arguments. A description of
            accepted keywords is provided below.


    Accepted keyword arguments:
        Direct keywords:
            - `zorder` the zorder of the bars and outline. The outline will be drawn on top of the bars.
            - `label` the label of the histogram. Note that the label is created as an emtpy artist to ensure
                consistensy with the label on 1-d histograms.
            - `linestyle`, `linewidth` the linestyle and linewidth of the outline and baseline. Can be set
                individually using the prefix `outline_` and `baseline_` respectively.


        Prefixed keywords:
            - `fill_<keyword>`: Keywords passed to [`PolarAxes.fill_between`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.PolarAxes.fill_between.html) when drawing the bars.
            - `outline_<keyword>`: Keywords passed to [`PolarAxes.plot`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.PolarAxes.plot.html) when drawing the outline.
            - `baseline_<keyword>`: Keywords passed to [`PolarAxes.plot`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.PolarAxes.plot.html) when drawing the baseline.
            - `rtext_<keyword>`: Keywords passed to [`PolarAxes.rtext`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.PolarAxes.rtext.html) when drawing the text label.



    """
    kwargs = utils.DefaultKwargs.Dict(kwargs)
    if r is None:
        r = self._last_hist_r + 1
    self._last_hist_r = r

    if outline is None:
        if fill and not cmap:
            outline = False
        else:
            outline = True

    if color is None:
        color = next(self._bar_color_cycle)

    rtext_kwargs = kwargs.pop_many(prefix='rtext')

    zorder = kwargs.pop('zorder', 1)
    fill_kwargs = kwargs.pop_many(prefix='fill', linestyle='', zorder=zorder)
    outline_kwargs = kwargs.pop_many(prefix='outline',
                                     color=color,
                                     linestyle=kwargs.pop('linestyle', '-'),
                                     linewidth=kwargs.pop('linewidth', 1),
                                     zorder=zorder + 0.001)
    baseline_kwargs = kwargs.pop_many(prefix='baseline', **outline_kwargs)

    bin_weights, bin_edges, bin_heights = self._mbins(m, r, weights, rheight, rscale, rescale, antipodal, bins,
                                                      update_rticks, minor_rticks)
    label = kwargs.pop('label', None)
    if (fill and not cmap) or outline:
        label_fill_kwargs = fill_kwargs.copy()
        if outline:
            label_fill_kwargs['linestyle'] = outline_kwargs['linestyle']
            label_fill_kwargs['linewidth'] = outline_kwargs['linewidth']
            label_fill_kwargs['edgecolor'] = outline_kwargs['color']
        if (fill and not cmap):
            label_fill_kwargs['fill'] = True
        else:
            label_fill_kwargs['fill'] = False

        self.fill([np.nan, np.nan], facecolor=color, label=label, **label_fill_kwargs)
    elif (fill and cmap) and rtext is None:
        rtext = label

    if fill:
        for i in range(bin_weights.size):
            if cmap:
                bin_color = self._cmap(self._norm(bin_weights[i]))
            else:
                bin_color = color

            self._rfill(bin_edges[i], bin_edges[i + 1], r, r + bin_heights[i],
                        color=bin_color, **fill_kwargs)

    if outline:
        theta_, r_ = np.array([]), np.array([])
        for i in range(bin_weights.size):
            tr = self._rline(bin_edges[i], bin_edges[i + 1], r + bin_heights[i])
            theta_, r_ = np.append(theta_, tr[0]), np.append(r_, tr[1])
        theta_, r_ = np.append(theta_, [theta_[0]]), np.append(r_, [r_[0]])
        self.axes.plot(theta_, r_, **outline_kwargs)

        theta_, r_ = self._rline(bin_edges[0], bin_edges[-1], r)
        self.axes.plot(theta_, r_, **baseline_kwargs)

    # self.axrline(r, 0, np.pi*2, color='black', linewidth = 0.2)

    if rtext is not None:
        rtext_kwargs.setdefault('r', r + rheight / 2)
        self.rtext(rtext, **rtext_kwargs)

mline

mline(m, r=1, merr=None, antipodal=None, *, eline=True, efill=False, ecolor=None, elinestyle=':', elinewidth=None, ezorder=None, ealpha=0.1, **kwargs)

Draw a line along a slope.

Used matplotlibs plot method to draw the line(s).

Parameters:

  • m ((float, (float, float))) –

    Either a single slope or a tuple of x and y coordinates from which a slope will be calculated.

  • r ((float, (float, float)), default: 1 ) –

    If a single value is given a line will be drawn between the 0 and r. if a tuple of two values are given the line will be drawn between r[0] and r[1]. Note these are absolute coordinates.

  • merr

    The uncertainty of the slope.

  • eline

    If True lines will also be drawn for the uncertainty of the slope.

  • efill

    If True the area defined by the uncertainty of the slope will be shaded.

  • ecolor

    The color used for the uncertainty lines and/or the shaded area.

  • elinestyle

    The line style used for the uncertainty lines.

  • elinewidth

    The line width used for the uncertainty lines.

  • ezorder

    The z order width used for the uncertainty lines.

  • ealpha

    The alpha value for the shaded area.

  • antipodal

    Whether the antipodal data points will be drawn. By default, antipodal=True when m is a slope and antipodal=False when m is x,y coordinates.

  • **kwargs

    Additional keyword arguments passed to matplotlibs plot method.

Source code in simple/roseaxes.py
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
def mline(self, m, r=1, merr=None, antipodal=None, *, eline=True, efill=False,
          ecolor=None, elinestyle=":", elinewidth=None, ezorder=None, ealpha=0.1,
          **kwargs):
    """
    Draw a line along a slope.

    Used matplotlibs [plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html) method to
    draw the line(s).

    Args:
        m (float, (float, float)): Either a single slope or a tuple of *x* and *y*
            coordinates from which a slope will be calculated.
        r (float, (float, float)): If a single value is given a line will be drawn between the ``0`` and ``r``.
            if a tuple of two values are given the line will be drawn between ``r[0]`` and ``r[1]``. Note these
            are absolute coordinates.
        merr (): The uncertainty of the slope.
        eline (): If ``True`` lines will also be drawn for the uncertainty of the slope.
        efill (): If ``True`` the area defined by the uncertainty of the slope will be shaded.
        ecolor (): The color used for the uncertainty lines and/or the shaded area.
        elinestyle (): The line style used for the uncertainty lines.
        elinewidth (): The line width used for the uncertainty lines.
        ezorder (): The z order width used for the uncertainty lines.
        ealpha (): The alpha value for the shaded area.
        antipodal (): Whether the antipodal data points will be drawn. By default, ``antipodal=True`` when ``m`` is
            a slope and ``antipodal=False`` when ``m`` is *x,y* coordinates.
        **kwargs (): Additional keyword arguments passed to matplotlibs
            [plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html) method.
    """

    kwargs.setdefault('linestyle', '-')
    return self._mline(m, r, merr,
                       ecolor=ecolor, elinestyle=elinestyle, elinewidth=elinewidth,
                       ezorder=ezorder, ealpha=ealpha, efill=efill, eline=eline,
                       antipodal=antipodal, axline=False, **kwargs)

rtext

rtext(text, r, deg=0, rotation=None, **kwargs)
Source code in simple/roseaxes.py
543
544
545
546
547
548
549
550
551
552
553
554
def rtext(self, text, r, deg=0, rotation=None, **kwargs):
    deg = deg % 360

    if rotation is None:
        rotation = deg * -1
        if deg > 90 and deg < 270:
            rotation = (rotation + 180) % 360

    label_kw = {'text': text, 'xy': (deg2rad(deg), r),
                'ha': 'center', 'va': 'center', 'rotation': rotation}
    label_kw.update(kwargs)
    self.annotate(**label_kw)

set_colorbar

set_colorbar(vmin=None, vmax=None, log=False, cmap='turbo', label=None, fontsize=None, show=True, ax=None, clear=True)

Define the colorbar used for histograms.

Currently, there is no way to delete any existing colorbars. Thus, everytime this function is called a new colorbar is created. Therefore, It's advisable to only call this method once.

Parameters:

  • vmin (float, default: None ) –

    The lower limit of the colour map. If no value is given the minimum value is 0 (or 1E-10 if log=True)

  • vmax (float, default: None ) –

    The upper limit of the colour map. If no value is given then vmax is set to 1 and all bin default_weight are divided by the heaviest bin weight in each histogram.

  • log (bool, default: False ) –

    Whether the color map scale is logarithmic or not.

  • cmap

    The prefixes of the colormap to use. See, [matplotlib documentation][https://matplotlib.org/stable/users/explain/colors/colormaps.html] for a list of available colormaps.

  • label

    The label given to the colorbar.

  • fontsize

    The fontsize of the colorbar label.

  • show

    Whether to add a colorbar to the figure.

  • ax

    The axis where the colorbar is drawn. If None it will be drawn on the right of the current axes.

  • clear

    If True the current axes will be cleared.

Source code in simple/roseaxes.py
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def set_colorbar(self, vmin=None, vmax=None, log=False, cmap='turbo',
                 label=None, fontsize=None, show=True, ax=None, clear=True):
    """
    Define the colorbar used for histograms.

    Currently, there is no way to delete any existing colorbars. Thus, everytime this function is called a new
    colorbar is created. Therefore, It's advisable to only call this method once.

    Args:
        vmin (float): The lower limit of the colour map. If no value is given the minimum value is ``0`` (or ``1E-10`` if
            ``log=True``)
        vmax (float): The upper limit of the colour map. If no value is given then ``vmax`` is set to ``1`` and all bin
            default_weight are divided by the heaviest bin weight in each histogram.
        log (bool): Whether the color map scale is logarithmic or not.
        cmap (): The prefixes of the colormap to use. See,
            [matplotlib documentation][https://matplotlib.org/stable/users/explain/colors/colormaps.html]
            for a list of available colormaps.
        label (): The label given to the colorbar.
        fontsize (): The fontsize of the colorbar label.
        show (): Whether to add a colorbar to the figure.
        ax (): The axis where the colorbar is drawn. If ``None`` it will be drawn on the right of the current axes.
        clear (): If ``True`` the current axes will be cleared.
    """
    self._vrel = True if vmax is None else False
    if log:
        self._vmin, self._vmax = vmin or 1E-10, vmax or 1
        self._norm = mpl.colors.LogNorm(vmin=self._vmin, vmax=self._vmax)
    else:
        self._vmin, self._vmax = vmin or 0, vmax or 1
        self._norm = mpl.colors.Normalize(vmin=self._vmin, vmax=self._vmax)

    self._cmap = get_cmap(cmap)
    if show:
        self._colorbar = self.get_figure().colorbar(mpl.cm.ScalarMappable(norm=self._norm, cmap=self._cmap),
                                                    ax=self, cax=ax, pad=0.1)
        self._colorbar.set_label(label, fontsize=fontsize)

    if clear:
        self.clear()

set_rres

set_rres(rres)

Set the resolution of lines drawn along the radius r. The number of points in a line is calculated as r*rres+1 (Min. 2).

Source code in simple/roseaxes.py
272
273
274
275
276
277
def set_rres(self, rres):
    """
    Set the resolution of lines drawn along the radius ``r``. The number of points in a line is calculated as
    ``r*rres+1`` (Min. 2).
    """
    self._rres = rres

set_xyscale

set_xyscale(xscale, yscale)

Set the scale of the x and y dimensions of the rose diagram.

This can be used to distort the diagram to e.g. better show large or small slopes.

Note Should not be confused with matplotlibs set_xscale and the set_yscale methods. They are used to set the type of scale, e.g. log, linear etc., used for the different axis.

Calling this method will clear the current axes as it cannot update what has already been drawn.

Parameters:

  • xscale (float) –

    The scale of the x dimension of the rose diagram.

  • yscale (float) –

    The scale of the y dimension of the rose diagram.

Source code in simple/roseaxes.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def set_xyscale(self, xscale, yscale):
    """
    Set the scale of the *x* and *y* dimensions of the rose diagram.

    This can be used to distort the diagram to e.g. better show large or small slopes.

    **Note** Should not be confused with matplotlibs ``set_xscale`` and the ``set_yscale`` methods. They
    are used to set the type of scale, e.g. log, linear etc., used for the different axis.

    Calling this method will clear the current axes as it cannot update what has already been drawn.

    Args:
        xscale (float): The scale of the *x* dimension of the rose diagram.
        yscale (float): The scale of the *y* dimension of the rose diagram.
    """
    # Not to be confused with set_xscale. This does something different.
    self._xscale = xscale
    self._yscale = yscale
    self.clear()

set_xysegment

set_xysegment(segment)

Define which segment of the rose diagram to show.

Parameters:

  • segment

    Options are N, E, S, W, None. If None the entire circle is shown.

Source code in simple/roseaxes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def set_xysegment(self, segment):
    """
    Define which segment of the rose diagram to show.

    Args:
        segment (): Options are ``N``, ``E``, ``S``, ``W``, ``None``.
            If ``None`` the entire circle is shown.
    """
    if segment is None:
        self.axes.set_thetagrids((0, 90, 180, 270),
                                 (self._yscale, self._xscale, self._yscale * -1, self._xscale * -1))
    elif type(segment) is not str:
        raise TypeError('segment must be a string')
    elif segment.upper() == 'N':
        self.axes.set_thetalim(-np.pi * 0.5, np.pi * 0.5)
        self.axes.set_thetagrids((-90, 0, 90), (-self._xscale, self._yscale, self._xscale))
    elif segment.upper() == 'S':
        self.axes.set_thetalim((np.pi * 0.5, np.pi * 1.5))
        self.axes.set_thetagrids((90, 180, 270), (-self._xscale, -self._yscale, self._xscale))
    elif segment.upper() == 'E':
        self.axes.set_thetalim(0, np.pi)
        self.axes.set_thetagrids((0, 90, 180), (self._yscale, self._xscale, -self._yscale))
    elif segment.upper() == 'W':
        self.axes.set_thetalim(np.pi, np.pi * 2)
        self.axes.set_thetagrids((180, 270, 360), (-self._yscale, -self._xscale, self._yscale))
    elif segment.upper() == 'NE':
        self.axes.set_thetalim(0, np.pi * 0.5)
        self.axes.set_thetagrids((0, 90), (self._yscale, self._xscale))
    elif segment.upper() == 'SE':
        self.axes.set_thetalim(np.pi * 0.5, np.pi)
        self.axes.set_thetagrids((90, 180), (self._xscale, -self._yscale))
    elif segment.upper() == 'SW':
        self.axes.set_thetalim(np.pi, np.pi * 1.5)
        self.axes.set_thetagrids((180, 270), (-self._yscale, -self._xscale))
    elif segment.upper() == 'NW':
        self.axes.set_thetalim(np.pi * 1.5, np.pi * 2)
        self.axes.set_thetagrids((270, 360), (-self._xscale, self._yscale))
    else:
        raise ValueError(f'Unknown segment: {segment}')
    self._xysegment = segment

simple.roseaxes.as0darray

as0darray(*a, dtype=np.float64)
Source code in simple/roseaxes.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def as0darray(*a, dtype=np.float64):
    out = [np.asarray(x, dtype=dtype) if x is not None else x for x in a]

    for o in out:
        if o is None:
            continue
        if o.ndim >= 1 and o.size != 1:
            raise ValueError('Size of arrays must be 1')

    out = tuple(o if (o is None or o.ndim == 0) else o.reshape(tuple()) for o in out)
    if len(out) == 1:
        return out[0]
    else:
        return out

simple.roseaxes.as1darray

as1darray(*a, dtype=np.float64)
Source code in simple/roseaxes.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def as1darray(*a, dtype=np.float64):
    size = None

    out = [np.asarray(x, dtype=dtype) if x is not None else x for x in a]

    for o in out:
        if o is None:
            continue
        if o.ndim == 1 and o.size != 1:
            if size is None:
                size = o.size
            elif o.size != size:
                raise ValueError('Size of arrays do not match')
        elif o.ndim > 1:
            raise ValueError('array cannot have more than 1 dimension')

    out = tuple(o if (o is None or (o.ndim == 1 and o.size != 1)) else np.full(size or 1, o) for o in out)
    if len(out) == 1:
        return out[0]
    else:
        return out

simple.roseaxes.deg2rad

deg2rad(deg)

Convert a degree angle into a radian angle`value

Source code in simple/roseaxes.py
83
84
85
def deg2rad(deg):
    """Convert a degree angle into a radian angle`value"""
    return np.deg2rad(deg)

simple.roseaxes.get_cmap

get_cmap(name)

Return the matplotlib colormap with the given name.

Source code in simple/roseaxes.py
93
94
95
96
97
98
def get_cmap(name):
    """Return the matplotlib colormap with the given name."""
    try:
        return mpl.colormaps[name]
    except:
        return mpl.cm.get_cmap(name)

simple.roseaxes.rad2deg

rad2deg(rad)

Convert a degree angle into a radian angle`value

Source code in simple/roseaxes.py
88
89
90
def rad2deg(rad):
    """Convert a degree angle into a radian angle`value"""
    return np.rad2deg(rad)

simple.roseaxes.xy2deg

xy2deg(x, y, xscale=1.0, yscale=1.0)

Convert x, y coordinated into a angle value given in degrees.

Source code in simple/roseaxes.py
75
76
77
78
79
80
def xy2deg(x, y, xscale=1.0, yscale=1.0):
    """
        Convert *x*, *y* coordinated into a angle value given in degrees.
        """
    rad = xy2rad(x, y, xscale=xscale, yscale=yscale)
    return rad2deg(rad)

simple.roseaxes.xy2rad

xy2rad(x, y, xscale=1.0, yscale=1.0)

Convert x, y coordinated into a angle value given in radians.

Source code in simple/roseaxes.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def xy2rad(x, y, xscale=1.0, yscale=1.0):
    """
    Convert *x*, *y* coordinated into a angle value given in radians.
    """

    def calc(x, y):
        if x == 0:
            return 0
        if y == 0:
            return np.pi / 2

        if x > 0:
            return np.pi * 0.5 - np.arctan(y / x)
        else:
            return np.pi * 1.5 - np.arctan(y / x)

    x, y = as1darray(x, y)
    return np.array([calc(x[i] / xscale, y[i] / yscale) for i in range(x.size)])