straditize.cross_mark module¶
Module for a cross mark to select one point in a matplotlib axes
Disclaimer
Copyright (C) 2018-2019 Philipp S. Sommer
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Classes
|
A CrossMarks that opens a QInputDialog after changing the position |
|
A set of draggable marks in a matplotlib axes |
|
A draggable horizontal line |
|
A CrossMarks that opens a QInputDialog after changing the position |
|
A draggable vertical line |
|
A CrossMarks that opens a QInputDialog after changing the position |
-
class
straditize.cross_mark.
CrossMarkText
(*args, **kwargs)[source]¶ Bases:
straditize.cross_mark.CrossMarks
A CrossMarks that opens a QInputDialog after changing the position
- Parameters
pos (tuple of 2 arrays) – The initial positions of the crosses. The first item marks the x-coordinates of the points, the second the y-coordinates
ax (matplotlib.axes.Axes) – The axes object to draw to. If not specified and draw_lines is True, the current axes object is used
selectable (list of {'x', 'y'}) – Determine whether only the x-, y-, or both lines should be selectable
draggable (list of {'x', 'y'}) – Determine whether only the x-, y-, or both lines should be draggable
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
functiondtype (object) – The data type for the data conversion
message (str) – The message to display in the dialog
label (str) – The label to how this value should be named
value (float) – The initial value to use
Methods
ask_for_value
([val, label])Ask for a value for the cross mark
on_release
(event, *args, **kwargs)Release the mark and unselect it
Attributes
The value of this cross mark
-
ask_for_value
(val=None, label=None)[source]¶ Ask for a value for the cross mark
This method opens a QInputDialog to ask for a new
value
-
on_release
(event, *args, **kwargs)[source]¶ Release the mark and unselect it
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that releases the mark
force (bool) – If True, the mark is released although it does not contain the event
connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are released, too
draw (bool) – If True, the figure is drawn
**kwargs (*args,) – Any other parameter that is passed to the connected lines
-
value
= None¶ The value of this cross mark
-
class
straditize.cross_mark.
CrossMarks
(pos=(0, 0), ax=None, selectable=['h', 'v'], draggable=['h', 'v'], idx_h=None, idx_v=None, xlim=None, ylim=None, select_props={'c': 'r'}, auto_hide=False, connected_artists=[], lock=True, draw_lines=True, hide_vertical=None, hide_horizontal=None, **kwargs)[source]¶ Bases:
object
A set of draggable marks in a matplotlib axes
- Parameters
pos (tuple of 2 arrays) – The initial positions of the crosses. The first item marks the x-coordinates of the points, the second the y-coordinates
ax (matplotlib.axes.Axes) – The axes object to draw to. If not specified and draw_lines is True, the current axes object is used
selectable (list of {'x', 'y'}) – Determine whether only the x-, y-, or both lines should be selectable
draggable (list of {'x', 'y'}) – Determine whether only the x-, y-, or both lines should be draggable
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
function
Attributes
The matplotlib axes to plot on
Block the emitting of signals of this instance
a list of
matplotlib.artist.Artist
whose colors are changedThe
matplotlib.figure.Figure
that this mark plots onBoolean to control whether the horizontal lines should be hidden
Boolean to control whether the vertical lines should be hidden
The current horizontal line
the list of horizontal lines
The index for vertical lines
The index for horizontal lines
The line connections to the current position
Class attribute that is set to a
CrossMark
instance to lock theA signal that is emitted when the mark is moved.
All other connections to the current position
The x-y-coordinates of the points as a (N, 2)-shaped array
The position of the current line
A boolean to control whether the connected artists should be shown
The current vertical line
the list of vertical lines
The x-position of the mark
The x-limits of the
hlines
The y-position of the mark
The x-limits of the
vlines
Methods
connect
()Connect the marks matplotlib events
connect_marks
(marks[, visible])Connect multiple marks to each other
connect_to_marks
(marks[, visible, append])Append other marks that should be considered for aligning the lines
contains
(event)Test if the mark is selected by the given event
Disconnect all the stored connection ids
draw_lines
(**kwargs)Draw the vertical and horizontal lines
is_selected_by
(event[, buttons])Test if the given event selects the mark
maintain_x
(marks)Connect marks and maintain a constant horizontal distance
maintain_y
(marks)Connect marks and maintain a constant vertical distance between them
on_motion
(event[, force, move_connected, …])Move the lines of this mark
on_press
(event[, force, connected])Select the mark
on_release
(event[, force, connected, draw])Release the mark and unselect it
remove
([artists])Remove all lines and disconnect the mark
set_connected_artists
(artists)Set the connected artists
set_connected_artists_visible
(visible)Set the visibility of the connected artists
set_current_point
(x, y[, nearest])Set the current point that is selected
set_pos
(pos)Move the point(s) to another position
set_visible
(b)Set the visibility of the mark
-
ax
= None¶ The matplotlib axes to plot on
-
property
block_signals
¶ Block the emitting of signals of this instance
-
static
connect_marks
(marks, visible=False)[source]¶ Connect multiple marks to each other
- Parameters
marks (list of CrossMarks) – A list of marks
visible (bool) – If True, the marks are connected through visible lines
Notes
Different from the
connect_to_marks()
method, this static function connects each of the marks to the others.
-
connect_to_marks
(marks, visible=False, append=True)[source]¶ Append other marks that should be considered for aligning the lines
- Parameters
Notes
This method can only be used to connect other marks with this mark. If you want to connect multiple marks within each other, use the
connect_marks()
static method
-
connected_artists
= []¶ a list of
matplotlib.artist.Artist
whose colors are changed when this mark is selected
-
contains
(event)[source]¶ Test if the mark is selected by the given event
- Parameters
event (ButtonPressEvent) – The ButtonPressEvent that has been triggered
-
draw_lines
(**kwargs)[source]¶ Draw the vertical and horizontal lines
- Parameters
**kwargs – An keyword that is passed to the
matplotlib.pyplot.plot()
function
-
property
fig
¶ The
matplotlib.figure.Figure
that this mark plots on
-
hide_horizontal
= False¶ Boolean to control whether the horizontal lines should be hidden
-
hide_vertical
= False¶ Boolean to control whether the vertical lines should be hidden
-
property
hline
¶ The current horizontal line
-
hlines
= []¶ the list of horizontal lines
-
property
idx_h
¶ The index for vertical lines
-
property
idx_v
¶ The index for horizontal lines
-
is_selected_by
(event, buttons=[1])[source]¶ Test if the given event selects the mark
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The matplotlib event
button (list of int) – Possible buttons to select this mark
- Returns
True, if it is selected
- Return type
-
property
line_connections
¶ The line connections to the current position
-
lock
= None¶ Class attribute that is set to a
CrossMark
instance to lock the selection of marks
-
static
maintain_x
(marks)[source]¶ Connect marks and maintain a constant horizontal distance
- Parameters
marks (list of CrossMarks) – A list of marks. If one of the marks is moved horizontally, the others are, too
-
static
maintain_y
(marks)[source]¶ Connect marks and maintain a constant vertical distance between them
- Parameters
marks (list of CrossMarks) – A list of marks. If one of the marks is moved vertically, the others are, too
-
moved
¶ A signal that is emitted when the mark is moved. Connected function are expected to accept two arguments. One tuple with the old position and the CrossMarks instance itself
-
on_motion
(event, force=False, move_connected=True, restore=True)[source]¶ Move the lines of this mark
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that moves the mark
force (bool) – If True, the mark is moved although it does not contain the event
move_connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are moved, too
restore (bool) – If True, the axes background is restored
-
on_press
(event, force=False, connected=True)[source]¶ Select the mark
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that selects the mark
force (bool) – If True, the mark is selected although it does not contain the event
connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are selected, too
-
on_release
(event, force=False, connected=True, draw=True, *args, **kwargs)[source]¶ Release the mark and unselect it
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that releases the mark
force (bool) – If True, the mark is released although it does not contain the event
connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are released, too
draw (bool) – If True, the figure is drawn
**kwargs (*args,) – Any other parameter that is passed to the connected lines
-
property
other_connections
¶ All other connections to the current position
-
property
points
¶ The x-y-coordinates of the points as a (N, 2)-shaped array
-
property
pos
¶ The position of the current line
-
remove
(artists=True)[source]¶ Remove all lines and disconnect the mark
- Parameters
artists (bool) – If True, the
connected_artists
list is cleared and the corresponding artists are removed as well
-
set_connected_artists
(artists)[source]¶ Set the connected artists
- Parameters
artists (matplotlib.artist.Artist) – The artists (e.g. other lines) that should be connected and highlighted if this mark is selected
-
set_connected_artists_visible
(visible)[source]¶ Set the visibility of the connected artists
- Parameters
visible (bool) – True, show the connected artists, else don’t
-
set_pos
(pos)[source]¶ Move the point(s) to another position
- Parameters
pos (tuple of 2 arrays) – The positions of the crosses. The first item marks the x-coordinates of the points, the second the y-coordinates
-
set_visible
(b)[source]¶ Set the visibility of the mark
- Parameters
b (bool) – If False, hide all horizontal and vertical lines, and the
connected_artists
-
show_connected_artists
= True¶ A boolean to control whether the connected artists should be shown at all
-
property
vline
¶ The current vertical line
-
vlines
= []¶ the list of vertical lines
-
property
x
¶ The x-position of the mark
-
property
y
¶ The y-position of the mark
-
class
straditize.cross_mark.
DraggableHLine
(y, ax=None, *args, **kwargs)[source]¶ Bases:
straditize.cross_mark.CrossMarks
A draggable horizontal line
- Parameters
y (float) – The y-position for the horizontal line
ax (matplotlib.axes.Axes) – The matplotlib axes
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
function
Attributes
bool(x) -> bool
The x-position of the mark
Methods
set_visible
(b)Set the visibility of the mark
-
hide_vertical
= True¶
-
set_visible
(b)[source]¶ Set the visibility of the mark
- Parameters
b (bool) – If False, hide all horizontal and vertical lines, and the
connected_artists
-
property
x
¶ The x-position of the mark
-
class
straditize.cross_mark.
DraggableHLineText
(*args, **kwargs)[source]¶ Bases:
straditize.cross_mark.DraggableHLine
A CrossMarks that opens a QInputDialog after changing the position
- Parameters
y (float) – The y-position for the horizontal line
ax (matplotlib.axes.Axes) – The matplotlib axes
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
functiondtype (object) – The data type for the data conversion
message (str) – The message to display in the dialog
label (str) – The label to how this value should be named
value (float) – The initial value to use
Methods
ask_for_value
([val, label])Ask for a value for the cross mark
on_release
(event, *args, **kwargs)Release the mark and unselect it
-
ask_for_value
(val=None, label=None)[source]¶ Ask for a value for the cross mark
This method opens a QInputDialog to ask for a new
value
-
on_release
(event, *args, **kwargs)[source]¶ Release the mark and unselect it
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that releases the mark
force (bool) – If True, the mark is released although it does not contain the event
connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are released, too
draw (bool) – If True, the figure is drawn
**kwargs (*args,) – Any other parameter that is passed to the connected lines
-
class
straditize.cross_mark.
DraggableVLine
(x, ax=None, *args, **kwargs)[source]¶ Bases:
straditize.cross_mark.CrossMarks
A draggable vertical line
- Parameters
x (float) – The x-position for the vertical line
ax (matplotlib.axes.Axes) – The matplotlib axes
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
function
Attributes
bool(x) -> bool
The y-position of the mark
Methods
set_visible
(b)Set the visibility of the mark
-
hide_horizontal
= True¶
-
set_visible
(b)[source]¶ Set the visibility of the mark
- Parameters
b (bool) – If False, hide all horizontal and vertical lines, and the
connected_artists
-
property
y
¶ The y-position of the mark
-
class
straditize.cross_mark.
DraggableVLineText
(*args, **kwargs)[source]¶ Bases:
straditize.cross_mark.DraggableVLine
A CrossMarks that opens a QInputDialog after changing the position
- Parameters
x (float) – The x-position for the vertical line
ax (matplotlib.axes.Axes) – The matplotlib axes
idx_h (pandas.Index) – The index for the horizontal coordinates. If not provided, we use a continuous movement along x.
idx_v (pandas.Index) – The index for the vertical coordinates. If not provided, we use a continuous movement along y.
xlim (tuple of floats (xmin, xmax)) – The minimum and maximum x value for the lines
ylim (tuple for floats (ymin, ymax)) – The minimum and maximum y value for the lines
select_props (color) – The line properties for selected marks
auto_hide (bool) – If True, the lines are hidden if they are not selected.
connected_artists (list of artists) – List of artists whose properties should be changed to select_props when this marks is selected
lock (bool) – If True, at most one mark can be selected at a time
draw_lines (bool) – If True, the cross mark lines are drawn. Otherwise, you must call the draw_lines method explicitly
hide_vertical (bool) – Boolean to control whether the vertical lines should be hidden. If None, the default class attribute is used
hide_horizontal (bool) – Boolean to control whether the horizontal lines should be hidden. If None, the default class attribute is used
**kwargs – Any other keyword argument that is passed to the
matplotlib.pyplot.plot()
functiondtype (object) – The data type for the data conversion
message (str) – The message to display in the dialog
label (str) – The label to how this value should be named
value (float) – The initial value to use
Methods
ask_for_value
([val, label])Ask for a value for the cross mark
on_release
(event, *args, **kwargs)Release the mark and unselect it
-
ask_for_value
(val=None, label=None)[source]¶ Ask for a value for the cross mark
This method opens a QInputDialog to ask for a new
value
-
on_release
(event, *args, **kwargs)[source]¶ Release the mark and unselect it
- Parameters
event (matplotlib.backend_bases.MouseEvent) – The mouseevent that releases the mark
force (bool) – If True, the mark is released although it does not contain the event
connected (bool) – If True, connected marks that should maintain a constant x- and y-distance are released, too
draw (bool) – If True, the figure is drawn
**kwargs (*args,) – Any other parameter that is passed to the connected lines