Thanks to visit codestin.com
Credit goes to github.com

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
pep8 compliance
Ran pep8.py 1.5.6 (https://github.com/jcrocholl/pep8) over the code.
Fixed all complaints.
  • Loading branch information
anykraus committed Apr 23, 2014
commit af30544731bbce7dc3956a43e3e2e8e74cdfbade
29 changes: 16 additions & 13 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,9 +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) #defaults to False, as it clobbers carefully hand crafted legends /2014-04-22
('(Re-)Generate automatic legend', False),
]

if has_curve:
Expand All @@ -72,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 @@ -100,7 +100,8 @@ def apply_callback(data):
general, = data

# Set / General
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale, generate_legend = general #/2014-04-22
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 @@ -114,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 @@ -124,12 +126,12 @@ def apply_callback(data):
line.set_markersize(markersize)
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)
# re-generate legend, if checkbox is checked. Stefan Kraus/tacaswell 2014-04-22

# 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 = axes.legend(ncol=old_legend._ncol)
new_legend.draggable(old_legend._draggable is not None)
else:
new_legend = axes.legend()
Expand All @@ -140,6 +142,7 @@ def apply_callback(data):
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)