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

Skip to content

Shade color #2745

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2834c09
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 Jan 19, 2014
c926ba5
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 Jan 19, 2014
d4233b8
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 May 16, 2015
eca57fe
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 May 16, 2015
3216669
using plt
Jul 11, 2015
90f63f8
pylab to plt
Jul 11, 2015
1ee2986
pylab to plt and np
Jul 11, 2015
0fa4b94
pylab to plt and np
Jul 11, 2015
1b72df1
pylab to plt and np
Jul 11, 2015
a0665f7
pylab to plt and np
Jul 11, 2015
8f2b84c
DOC: slightly update demo
tacaswell Jul 17, 2015
887e20d
DOC: whats_new for axes.labelpad
tacaswell Jul 17, 2015
188d7a1
DOC: protect against non-gui backends in demo
tacaswell Jul 17, 2015
b328cbb
pep8
Jul 17, 2015
5a5f458
pep8
Jul 17, 2015
b26a521
pep8
Jul 17, 2015
3720671
pep8
Jul 17, 2015
a7fa5d9
pep8
Jul 17, 2015
38215ef
pep8
Jul 17, 2015
0f726dc
Implement draw_idle
mdehoon Jul 17, 2015
0bbc091
Merge pull request #4731 from mdehoon/implementDrawIdle
tacaswell Jul 17, 2015
5cadac1
Merge pull request #4724 from tacaswell/doc_update_demo
jenshnielsen Jul 17, 2015
6e2ee31
Merge pull request #4739 from jkseppan/pdf-paint
efiring Jul 18, 2015
0a7af4e
Merge pull request #4726 from tacaswell/doc_axeslabelpad_doc
efiring Jul 18, 2015
a967158
Merge pull request #4654 from domspad/MEP12-on-annotation-demo2.py
jenshnielsen Jul 19, 2015
8dd9c29
Merge pull request #4663 from domspad/MEP12-on-axes_props.py
jenshnielsen Jul 19, 2015
d1d0122
Merge pull request #4657 from domspad/MEP12-on-anscombe.py
jenshnielsen Jul 19, 2015
b8d7e25
Merge pull request #4660 from domspad/MEP12-on-arrow_demo.py
jenshnielsen Jul 19, 2015
f37e6ef
Merge pull request #4664 from domspad/MEP12-on-axis_equal_demo.py
jenshnielsen Jul 19, 2015
708468b
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 Jan 19, 2014
1c70b15
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 Jan 19, 2014
badd1f8
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 May 16, 2015
49b9b25
NF - added new feature to colors called shade_color to lighten or dar…
dvreed77 May 16, 2015
913a3b4
merged changes
dvreed77 Jul 19, 2015
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
10 changes: 10 additions & 0 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ Testing
New plotting features
---------------------

Easy color shading
``````````````````
Often we would like the ability add subtle color variation to our plots,
especially when similar element are plotted in close proximity to one another.
:func:`matplotlib.colors.shade_color` can be used to take an existing color and
slightly darken it, by giving a negative percentage, or to slightly lighten it,
by giving a positive percentage.

.. plot:: mpl_examples/color/color_shade_demo.py

Copy link
Member

Choose a reason for hiding this comment

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

I see why this wants a rebase... Given that version 1.3 is listed at the top of your what's new file, I think you need to update your fork of matplotlib. Once you got your local repo all up to date, then rebase this branch off of the updated master. In that process, you should also move this entry to its own file, which we do now to avoid merge conflicts. We automatically assemble all of the what's new entry prior to release.

`xkcd`-style sketch plotting
````````````````````````````
To give your plots a sense of authority that they may be missing,
Expand Down
6 changes: 6 additions & 0 deletions doc/users/whats_new/rcparams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ Added "toolmanager" to "toolbar" possible values
````````````````````````````````````````````````

The new value enables the use of ``ToolManager``


Added ``axes.labelpad``
```````````````````````

This new value controls the space between the axis and the label
21 changes: 21 additions & 0 deletions examples/color/color_shade_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Demo of shade_color utility.

"""
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

fig = plt.figure()
ax = fig.add_subplot(111)

lightened_color = mcolors.shade_color('blue', -50)
darkened_color = mcolors.shade_color('blue', +50)

ax.fill_between([0,1], [0,0], [1,1], facecolor=darkened_color)
ax.fill_between([0,1], [0,0], [.66, .66], facecolor='blue')
ax.fill_between([0,1], [0,0], [.33, .33], facecolor=lightened_color)

plt.xlim([0, 1])
plt.ylim([0, 1])

plt.show()
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: add a newline at the end of this file.

10 changes: 5 additions & 5 deletions examples/pylab_examples/annotation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
"""


from matplotlib.pyplot import figure, show
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np


if 1:
# if only one location is given, the text and xypoint being
# annotated are assumed to be the same
fig = figure()
fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1, 5), ylim=(-3, 5))

t = np.arange(0.0, 5.0, 0.01)
Expand Down Expand Up @@ -93,7 +93,7 @@
# example is placed in the fractional figure coordinate system.
# Text keyword args like horizontal and vertical alignment are
# respected
fig = figure()
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
r = np.arange(0, 1, 0.001)
theta = 2*2*np.pi*r
Expand All @@ -120,7 +120,7 @@

el = Ellipse((0, 0), 10, 20, facecolor='r', alpha=0.5)

fig = figure()
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.add_artist(el)
el.set_clip_box(ax.bbox)
Expand All @@ -138,4 +138,4 @@
ax.set_xlim(-20, 20)
ax.set_ylim(-20, 20)

show()
plt.show()
14 changes: 7 additions & 7 deletions examples/pylab_examples/annotation_demo2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

from matplotlib.pyplot import figure, show
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np

if 1:
fig = figure(1, figsize=(8, 5))
fig = plt.figure(1, figsize=(8, 5))
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1, 5), ylim=(-4, 3))

t = np.arange(0.0, 5.0, 0.01)
Expand Down Expand Up @@ -80,7 +80,7 @@


if 1:
fig = figure(2)
fig = plt.figure(2)
fig.clf()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1, 5), ylim=(-5, 3))

Expand All @@ -98,7 +98,7 @@
ax.annotate('fancy', xy=(2., -1), xycoords='data',
xytext=(-100, 60), textcoords='offset points',
size=20,
#bbox=dict(boxstyle="round", fc="0.8"),
# bbox=dict(boxstyle="round", fc="0.8"),
arrowprops=dict(arrowstyle="fancy",
fc="0.6", ec="none",
patchB=el,
Expand All @@ -108,7 +108,7 @@
ax.annotate('simple', xy=(2., -1), xycoords='data',
xytext=(100, 60), textcoords='offset points',
size=20,
#bbox=dict(boxstyle="round", fc="0.8"),
# bbox=dict(boxstyle="round", fc="0.8"),
arrowprops=dict(arrowstyle="simple",
fc="0.6", ec="none",
patchB=el,
Expand All @@ -118,7 +118,7 @@
ax.annotate('wedge', xy=(2., -1), xycoords='data',
xytext=(-100, -100), textcoords='offset points',
size=20,
#bbox=dict(boxstyle="round", fc="0.8"),
# bbox=dict(boxstyle="round", fc="0.8"),
arrowprops=dict(arrowstyle="wedge,tail_width=0.7",
fc="0.6", ec="none",
patchB=el,
Expand Down Expand Up @@ -150,4 +150,4 @@
)


show()
plt.show()
63 changes: 32 additions & 31 deletions examples/pylab_examples/anscombe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,52 @@
matplotlib fun for a rainy day
"""

from pylab import *
import matplotlib.pyplot as plt
import numpy as np

x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y1 = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
y2 = array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74])
y3 = array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73])
x4 = array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8])
y4 = array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89])
x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])
y1 = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68])
y2 = np.array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74])
y3 = np.array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73])
x4 = np.array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8])
y4 = np.array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89])


def fit(x):
return 3 + 0.5*x


xfit = array([amin(x), amax(x)])
xfit = np.array([np.amin(x), np.amax(x)])

subplot(221)
plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
axis([2, 20, 2, 14])
setp(gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
text(3, 12, 'I', fontsize=20)
plt.subplot(221)
plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
plt.text(3, 12, 'I', fontsize=20)

subplot(222)
plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
axis([2, 20, 2, 14])
setp(gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20))
text(3, 12, 'II', fontsize=20)
plt.subplot(222)
plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20))
plt.text(3, 12, 'II', fontsize=20)

subplot(223)
plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
axis([2, 20, 2, 14])
text(3, 12, 'III', fontsize=20)
setp(gca(), yticks=(4, 8, 12), xticks=(0, 10, 20))
plt.subplot(223)
plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.text(3, 12, 'III', fontsize=20)
plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20))

subplot(224)
plt.subplot(224)

xfit = array([amin(x4), amax(x4)])
plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
axis([2, 20, 2, 14])
setp(gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
text(3, 12, 'IV', fontsize=20)
xfit = np.array([np.amin(x4), np.amax(x4)])
plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
plt.text(3, 12, 'IV', fontsize=20)

# verify the stats
pairs = (x, y1), (x, y2), (x, y3), (x4, y4)
for x, y in pairs:
print('mean=%1.2f, std=%1.2f, r=%1.2f' % (mean(y), std(y), corrcoef(x, y)[0][1]))
print('mean=%1.2f, std=%1.2f, r=%1.2f' % (np.mean(y), np.std(y), np.corrcoef(x, y)[0][1]))

show()
plt.show()
56 changes: 29 additions & 27 deletions examples/pylab_examples/arrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@


"""
from pylab import *
import matplotlib.pyplot as plt
import numpy as np

rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA', 'r6': 'AC',
'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC', 'r11': 'GC', 'r12': 'CG'}
rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA',
'r6': 'AC', 'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC',
'r11': 'GC', 'r12': 'CG'}
numbered_bases_to_rates = dict([(v, k) for k, v in rates_to_bases.items()])
lettered_bases_to_rates = dict([(v, 'r' + v) for k, v in rates_to_bases.items()])

Expand Down Expand Up @@ -45,17 +47,17 @@ def make_arrow_plot(data, size=4, display='length', shape='right',
linewidth and edgecolor.
"""

xlim(-0.5, 1.5)
ylim(-0.5, 1.5)
gcf().set_size_inches(size, size)
xticks([])
yticks([])
plt.xlim(-0.5, 1.5)
plt.ylim(-0.5, 1.5)
plt.gcf().set_size_inches(size, size)
plt.xticks([])
plt.yticks([])
max_text_size = size*12
min_text_size = size
label_text_size = size*2.5
text_params = {'ha': 'center', 'va': 'center', 'family': 'sans-serif',
'fontweight': 'bold'}
r2 = sqrt(2)
r2 = np.sqrt(2)

deltas = {
'AT': (1, 0),
Expand Down Expand Up @@ -103,13 +105,13 @@ def make_arrow_plot(data, size=4, display='length', shape='right',
}

def do_fontsize(k):
return float(clip(max_text_size*sqrt(data[k]),
return float(np.clip(max_text_size*np.sqrt(data[k]),
min_text_size, max_text_size))

A = text(0, 1, '$A_3$', color='r', size=do_fontsize('A'), **text_params)
T = text(1, 1, '$T_3$', color='k', size=do_fontsize('T'), **text_params)
G = text(0, 0, '$G_3$', color='g', size=do_fontsize('G'), **text_params)
C = text(1, 0, '$C_3$', color='b', size=do_fontsize('C'), **text_params)
A = plt.text(0, 1, '$A_3$', color='r', size=do_fontsize('A'), **text_params)
T = plt.text(1, 1, '$T_3$', color='k', size=do_fontsize('T'), **text_params)
G = plt.text(0, 0, '$G_3$', color='g', size=do_fontsize('G'), **text_params)
C = plt.text(1, 0, '$C_3$', color='b', size=do_fontsize('C'), **text_params)

arrow_h_offset = 0.25 # data coordinates, empirically determined
max_arrow_length = 1 - 2*arrow_h_offset
Expand All @@ -119,7 +121,7 @@ def do_fontsize(k):
max_head_length = 2*max_arrow_width
arrow_params = {'length_includes_head': True, 'shape': shape,
'head_starts_at_zero': head_starts_at_zero}
ax = gca()
ax = plt.gca()
sf = 0.6 # max arrow size represents this in data coords

d = (r2/2 + arrow_h_offset - 0.5)/r2 # distance for diags
Expand Down Expand Up @@ -179,7 +181,7 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):

x_scale, y_scale = deltas[pair]
x_pos, y_pos = positions[pair]
arrow(x_pos, y_pos, x_scale*length, y_scale*length,
plt.arrow(x_pos, y_pos, x_scale*length, y_scale*length,
fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width,
head_length=head_length, **arrow_params)

Expand All @@ -192,24 +194,24 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):

where = label_positions[pair]
if where == 'left':
orig_position = 3*array([[max_arrow_width, max_arrow_width]])
orig_position = 3*np.array([[max_arrow_width, max_arrow_width]])
elif where == 'absolute':
orig_position = array([[max_arrow_length/2.0, 3*max_arrow_width]])
orig_position = np.array([[max_arrow_length/2.0, 3*max_arrow_width]])
elif where == 'right':
orig_position = array([[length - 3*max_arrow_width,
orig_position = np.array([[length - 3*max_arrow_width,
3*max_arrow_width]])
elif where == 'center':
orig_position = array([[length/2.0, 3*max_arrow_width]])
orig_position = np.array([[length/2.0, 3*max_arrow_width]])
else:
raise ValueError("Got unknown position parameter %s" % where)

M = array([[cx, sx], [-sx, cx]])
coords = dot(orig_position, M) + [[x_pos, y_pos]]
x, y = ravel(coords)
M = np.array([[cx, sx], [-sx, cx]])
coords = np.dot(orig_position, M) + [[x_pos, y_pos]]
x, y = np.ravel(coords)
orig_label = rate_labels[pair]
label = '$%s_{_{\mathrm{%s}}}$' % (orig_label[0], orig_label[1:])

text(x, y, label, size=label_text_size, ha='center', va='center',
plt.text(x, y, label, size=label_text_size, ha='center', va='center',
color=labelcolor or fc)

for p in positions.keys():
Expand Down Expand Up @@ -302,11 +304,11 @@ def draw_arrow(pair, alpha=alpha, ec=ec, labelcolor=labelcolor):
display = 'length'

size = 4
figure(figsize=(size, size))
plt.figure(figsize=(size, size))

make_arrow_plot(d, display=display, linewidth=0.001, edgecolor=None,
normalize_data=scaled, head_starts_at_zero=True, size=size)

draw()
plt.draw()

show()
plt.show()
Loading