My favorites | Sign in
Project Home Downloads Wiki Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
#
# Copyright © 2009 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see pydeelib/__init__.py for details)

"""Module that provides a GUI-based editor for matplotlib's figure options"""

from pydeelib.widgets.formlayout import fedit

LINESTYLES = {
'-': 'Solid',
'--': 'Dashed',
'-.': 'DashDot',
':': 'Dotted',
'steps': 'Steps',
'none': 'None',
}

MARKERS = {
'none': 'None',
'o': 'circles',
'^': 'triangle_up',
'v': 'triangle_down',
'<': 'triangle_left',
'>': 'triangle_right',
's': 'square',
'+': 'plus',
'x': 'cross',
'*': 'star',
'D': 'diamond',
'd': 'thin_diamond',
'1': 'tripod_down',
'2': 'tripod_up',
'3': 'tripod_left',
'4': 'tripod_right',
'h': 'hexagon',
'H': 'rotated_hexagon',
'p': 'pentagon',
'|': 'vertical_line',
'_': 'horizontal_line',
'.': 'dots',
}

COLORS = {'b': '#0000ff', 'g': '#00ff00', 'r': '#ff0000', 'c': '#ff00ff',
'm': '#ff00ff', 'y': '#ffff00', 'k': '#000000', 'w': '#ffffff'}

def col2hex(color):
"""Convert matplotlib color to hex"""
return COLORS.get(color, color)

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

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

# Get / General
xmin, xmax = axes.get_xlim()
ymin, ymax = axes.get_ylim()
general = [('Title', axes.get_title()),
sep,
(None, "<b>X-Axis</b>"),
('Min', xmin), ('Max', xmax),
('Label', axes.get_xlabel()),
('Scale', [axes.get_xscale(), 'linear', 'log']),
sep,
(None, "<b>Y-Axis</b>"),
('Min', ymin), ('Max', ymax),
('Label', axes.get_ylabel()),
('Scale', [axes.get_yscale(), 'linear', 'log'])
]

if has_curve:
# Get / Curves
linedict = {}
for line in axes.get_lines():
label = line.get_label()
if label == '_nolegend_':
continue
linedict[label] = line
curves = []
linestyles = LINESTYLES.items()
markers = MARKERS.items()
curvelabels = sorted(linedict.keys())
for label in curvelabels:
line = linedict[label]
curvedata = [
('Label', label),
sep,
(None, '<b>Line</b>'),
('Style', [line.get_linestyle()] + linestyles),
('Width', line.get_linewidth()),
('Color', col2hex(line.get_color())),
sep,
(None, '<b>Marker</b>'),
('Style', [line.get_marker()] + markers),
('Size', line.get_markersize()),
('Facecolor', col2hex(line.get_markerfacecolor())),
('Edgecolor', col2hex(line.get_markeredgecolor())),
]
curves.append([curvedata, label, ""])

datalist = [(general, "Axes", "")]
if has_curve:
datalist.append((curves, "Curves", ""))
result = fedit(datalist, title="Figure options", parent=parent)
if result is None:
return

if has_curve:
general, curves = result
else:
general, = result

# Set / General
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
axes.set_xscale(xscale)
axes.set_yscale(yscale)
axes.set_title(title)
axes.set_xlim(xmin, xmax)
axes.set_xlabel(xlabel)
axes.set_ylim(ymin, ymax)
axes.set_ylabel(ylabel)

if has_curve:
# Set / Curves
for index, curve in enumerate(curves):
line = linedict[curvelabels[index]]
label, linestyle, linewidth, color, \
marker, markersize, markerfacecolor, markeredgecolor = curve
line.set_label(label)
line.set_linestyle(linestyle)
line.set_linewidth(linewidth)
line.set_color(color)
if marker is not 'none':
line.set_marker(marker)
line.set_markersize(markersize)
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)

# Redraw
canvas.draw()

Change log

7107d51c74e4 by Pierre Raybaut <p...@pythonxy.com> on May 31, 2009   Diff
Switch Pydee license to MIT license
Go to: 
Project members, sign in to write a code review

Older revisions

de7791e2f0e1 by Pierre Raybaut <p...@pythonxy.com> on May 30, 2009   Diff
'PyQtShell' module was renamed to
'pydeelib'
All revisions of this file

File info

Size: 4857 bytes, 145 lines
Powered by Google Project Hosting