def from_legend(cls, legend): props = dict() props['visible'] = legend.get_visible() title = legend.get_title() if sys.version_info[0] >= 3: if isinstance(title.get_text(), str): props['title'] = title.get_text() else: props['title'] = None else: if isinstance(title.get_text(), unicode): props['title'] = title.get_text() else: props['title'] = None props['title_font'] = title.get_fontname() props['title_size'] = title.get_fontsize() props['title_color'] = convert_color_to_hex(title.get_color()) props['box_visible'] = legend.get_frame_on() box = legend.get_frame() props['background_color'] = convert_color_to_hex(box.get_facecolor()) props['edge_color'] = convert_color_to_hex(box.get_edgecolor()) props['transparency'] = box.get_alpha() text = legend.get_texts()[0] props['entries_font'] = text.get_fontname() props['entries_size'] = text.get_fontsize() props['entries_color'] = convert_color_to_hex(text.get_color()) props['marker_size'] = legend.handlelength props['shadow'] = legend.shadow boxstyle = legend.legendPatch.get_boxstyle() if isinstance(boxstyle, BoxStyle.Round): props['round_edges'] = True else: props['round_edges'] = False props['columns'] = legend._ncol props['column_spacing'] = legend.columnspacing props['label_spacing'] = legend.labelspacing position = legend._legend_handle_box.get_children()[0].align if position == "baseline": props['marker_position'] = "Left of Entries" else: props['marker_position'] = "Right of Entries" props['markers'] = legend.numpoints props['border_padding'] = legend.borderpad props['marker_label_padding'] = legend.handletextpad return cls(props)
def test_apply_properties_on_figure_with_curve_sets_errorbar_color(self): cap_color = self.new_curve[1][0].get_color() bar_color = self.new_curve[2][0].get_color() if cap_color[0] != '#': cap_color = convert_color_to_hex(cap_color[0]) if bar_color[0] != '#': bar_color = convert_color_to_hex(bar_color[0]) self.assertEqual(new_curve_view_props['ecolor'], cap_color) self.assertEqual(new_curve_view_props['ecolor'], bar_color)
def test_apply_properties_on_figure_with_legend_sets_edge_color(self): if int(matplotlib.__version__[0]) >= 2: self.assertEqual( new_legend_props['edge_color'], convert_color_to_hex( self.new_legend.get_frame().get_edgecolor())) else: self.assertEqual( "#000000", convert_color_to_hex( self.new_legend.get_frame().get_edgecolor()))
def _get_marker_props_from_curve(curve, props): """Get a curve's marker properties and add to props dict""" if not curve: props['marker'] = 'None' props['markersize'] = rcParams['lines.markersize'] props['markerfacecolor'] = convert_color_to_hex(rcParams['lines.color']) props['markeredgecolor'] = convert_color_to_hex(rcParams['lines.color']) else: props['marker'] = get_marker_name(curve.get_marker()) props['markersize'] = curve.get_markersize() props['markerfacecolor'] = convert_color_to_hex(curve.get_markerfacecolor()) props['markeredgecolor'] = convert_color_to_hex(curve.get_markeredgecolor()) return props
def _get_line_props_from_curve(curve, props): """Get a curve's line properties and add to props dict""" if not curve: props['linestyle'] = 'None' props['drawstyle'] = 'default' props['linewidth'] = rcParams['lines.linewidth'] props['color'] = convert_color_to_hex(rcParams['lines.color']) else: props['linestyle'] = LINESTYLE_MAP[curve.get_linestyle()] props['drawstyle'] = curve.get_drawstyle() props['linewidth'] = curve.get_linewidth() props['color'] = convert_color_to_hex(curve.get_color()) return props
def _get_errorbars_props_from_curve(curve, props): """Get a curve's errorbar properties and add to props dict""" props['hide_errors'] = getattr(curve, 'hide_errors', errorbars_hidden(curve)) # ErrorbarContainer does not have 'errorevery' as an attribute directly # So to get this property take from errorbar lines curve try: barlines = curve[2][0] props['errorevery'] = int( barlines.axes.creation_args[len(barlines.axes.creation_args) - 1]['errorevery']) except (IndexError, TypeError, KeyError): props['errorevery'] = 1 try: caps = curve[1] props['capsize'] = float(caps[0].get_markersize() / 2) props['capthick'] = float(caps[0].get_markeredgewidth()) except (IndexError, TypeError): props['capsize'] = 0.0 props['capthick'] = 1.0 try: bars = curve[2] props['elinewidth'] = float(bars[0].get_linewidth()[0]) props['ecolor'] = convert_color_to_hex(bars[0].get_color()[0]) except (IndexError, TypeError): props['elinewidth'] = 1.0 # if the errorbars don't have a default color, use the line's color props['ecolor'] = curve.get_color() return props
def get_subplots_command_kwargs(fig): ax = fig.get_axes()[0] kwargs = { 'dpi': fig.dpi, 'edgecolor': convert_color_to_hex(fig.get_edgecolor()), 'facecolor': convert_color_to_hex(fig.get_facecolor()), 'figsize': [fig.get_figwidth(), fig.get_figheight()], 'frameon': fig.frameon, 'ncols': ax.numCols, 'nrows': ax.numRows, 'num': fig.get_label(), 'subplot_kw': { 'projection': 'mantid' }, } return kwargs
def _get_errorbars_props_from_curve(curve, props): """Get a curve's errorbar properties and add to props dict""" props['hide_errors'] = getattr(curve, 'hide_errors', errorbars_hidden(curve)) props['errorevery'] = getattr(curve, 'errorevery', 1) try: caps = curve[1] props['capsize'] = float(caps[0].get_markersize() / 2) props['capthick'] = float(caps[0].get_markeredgewidth()) except (IndexError, TypeError): props['capsize'] = 0.0 props['capthick'] = 1.0 try: bars = curve[2] props['elinewidth'] = float(bars[0].get_linewidth()[0]) props['ecolor'] = convert_color_to_hex(bars[0].get_color()[0]) except (IndexError, TypeError): props['elinewidth'] = 1.0 props['ecolor'] = convert_color_to_hex(rcParams['lines.color']) return props
def init_view(self): # This function sets the correct values in the menu when it is first opened. if self.ax.waterfall_has_fill(): self.view.enable_fill_group_box.setChecked(True) if datafunctions.waterfall_fill_is_line_colour(self.ax): self.view.use_line_colour_radio_button.setChecked(True) else: self.view.use_solid_colour_radio_button.setChecked(True) poly = next(poly_collection for poly_collection in self.ax.collections if isinstance(poly_collection, PolyCollection)) self.view.colour_selector_widget.set_color(convert_color_to_hex(poly.get_facecolor().tolist()[0]))
def test_get_plot_kwargs(self): expected_dict = { 'capsize': 0, 'capthick': 1, 'color': '#ff0000', 'drawstyle': u'steps', 'ecolor': convert_color_to_hex(rcParams['lines.color']), 'elinewidth': 1, 'errorevery': 1, 'label': 'ax0', 'linestyle': 'dashdot', 'linewidth': 4, 'marker': 'triangle_down', 'markeredgecolor': '#008000', 'markerfacecolor': '#000000', 'markersize': 10, 'visible': False } self.assertEqual(expected_dict, self.props.get_plot_kwargs())
def test_changing_line_colour_on_a_waterfall_plot_with_filled_areas_changes_fill_colour_to_match(self): fig = self.make_figure_with_multiple_curves() mock_view = Mock(get_selected_ax_name=lambda: "Axes 0: (0, 0)", get_selected_curve_name=lambda: "Workspace") ax = fig.get_axes()[0] ax.lines[0].set_color('#ff9900') ax.lines[1].set_color('#008fff') ax.lines[2].set_color('#42ff00') # Create waterfall plot and add filled areas. ax.set_waterfall(True) ax.set_waterfall_fill(True) presenter = self._generate_presenter(fig=fig, mock_view=mock_view) # Change the colour of one of the lines. new_plot_kwargs = {'color': '#ffff00'} presenter._replot_selected_curve(new_plot_kwargs) # The fill for that line should be the new colour. self.assertEqual(convert_color_to_hex(ax.collections[0].get_facecolor()[0]), ax.lines[0].get_color())
# NScD Oak Ridge National Laboratory, European Spallation Source, # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # SPDX - License - Identifier: GPL - 3.0 + # This file is part of the mantid workbench. from matplotlib import rcParams from numpy import isclose from mantidqt.widgets.plotconfigdialog.colorselector import convert_color_to_hex from workbench.plotting.plotscriptgenerator.utils import convert_args_to_string BASE_SUBPLOTS_COMMAND = "plt.subplots({})" default_kwargs = { 'dpi': rcParams['figure.dpi'], 'edgecolor': convert_color_to_hex(rcParams['figure.edgecolor']), 'facecolor': convert_color_to_hex(rcParams['figure.facecolor']), 'figsize': rcParams['figure.figsize'], 'frameon': rcParams['figure.frameon'], 'ncols': 1, 'nrows': 1, 'num': '' } def get_subplots_command_kwargs(fig): ax = fig.get_axes()[0] kwargs = { 'dpi': fig.dpi, 'edgecolor': convert_color_to_hex(fig.get_edgecolor()), 'facecolor': convert_color_to_hex(fig.get_facecolor()),