Skip to content

Re-Generate legend, through apply_callback/Apply #2947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions lib/matplotlib/backends/qt4_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
from matplotlib.backends.qt4_compat import QtGui
from matplotlib import markers


def get_icon(name):
import matplotlib
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
return QtGui.QIcon(osp.join(basedir, name))

LINESTYLES = {
'-': 'Solid',
LINESTYLES = {'-': 'Solid',
'--': 'Dashed',
'-.': 'DashDot',
':': 'Dotted',
Expand All @@ -34,9 +34,10 @@ def get_icon(name):

MARKERS = markers.MarkerStyle.markers


def figure_edit(axes, parent=None):
"""Edit matplotlib figure options"""
sep = (None, None) # separator
sep = (None, None) # separator

has_curve = len(axes.get_lines()) > 0

Expand All @@ -53,7 +54,9 @@ def figure_edit(axes, parent=None):
(None, "<b>Y-Axis</b>"),
('Min', ymin), ('Max', ymax),
('Label', axes.get_ylabel()),
('Scale', [axes.get_yscale(), 'linear', 'log'])
('Scale', [axes.get_yscale(), 'linear', 'log']),
sep,
('(Re-)Generate automatic legend', False),
]

if has_curve:
Expand All @@ -70,8 +73,7 @@ def figure_edit(axes, parent=None):
curvelabels = sorted(linedict.keys())
for label in curvelabels:
line = linedict[label]
curvedata = [
('Label', label),
curvedata = [('Label', label),
sep,
(None, '<b>Line</b>'),
('Style', [line.get_linestyle()] + linestyles),
Expand All @@ -98,7 +100,8 @@ def apply_callback(data):
general, = data

# Set / General
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale, \
generate_legend = general
axes.set_xscale(xscale)
axes.set_yscale(yscale)
axes.set_title(title)
Expand All @@ -112,7 +115,8 @@ def apply_callback(data):
for index, curve in enumerate(curves):
line = linedict[curvelabels[index]]
label, linestyle, linewidth, color, \
marker, markersize, markerfacecolor, markeredgecolor = curve
marker, markersize, markerfacecolor, markeredgecolor \
= curve
line.set_label(label)
line.set_linestyle(linestyle)
line.set_linewidth(linewidth)
Expand All @@ -123,11 +127,22 @@ def apply_callback(data):
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)

# re-generate legend, if checkbox is checked
if generate_legend:
if axes.legend_ is not None:
old_legend = axes.get_legend()
new_legend = axes.legend(ncol=old_legend._ncol)
new_legend.draggable(old_legend._draggable is not None)
else:
new_legend = axes.legend()
new_legend.draggable(True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want to default to draggable legends


# Redraw
figure = axes.get_figure()
figure.canvas.draw()

data = formlayout.fedit(datalist, title="Figure options", parent=parent,
icon=get_icon('qt4_editor_options.svg'), apply=apply_callback)
icon=get_icon('qt4_editor_options.svg'),
apply=apply_callback)
if data is not None:
apply_callback(data)
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
'*/matplotlib/backends/qt4_compat.py',
'*/matplotlib/backends/tkagg.py',
'*/matplotlib/backends/windowing.py',
'*/matplotlib/backends/qt4_editor/figureoptions.py',
'*/matplotlib/backends/qt4_editor/formlayout.py',
'*/matplotlib/sphinxext/ipython_console_highlighting.py',
'*/matplotlib/sphinxext/ipython_directive.py',
Expand Down