Skip to content

Commit

Permalink
Merge pull request #2947 from anykraus/debug
Browse files Browse the repository at this point in the history
Re-Generate legend, through apply_callback/Apply
  • Loading branch information
tacaswell committed May 2, 2014
2 parents a6a09c1 + 9ede5be commit 0fa7771
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
33 changes: 24 additions & 9 deletions lib/matplotlib/backends/qt4_editor/figureoptions.py
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)

# 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
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

0 comments on commit 0fa7771

Please sign in to comment.