Skip to content

Commit

Permalink
Merge remote-tracking branch 'matplotlib/v2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Jun 19, 2016
2 parents 25ce666 + 74ead7c commit a72574d
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 48 deletions.
2 changes: 2 additions & 0 deletions examples/api/collections_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]

fig, axes = plt.subplots(2, 2)
fig.subplots_adjust(top=0.92, left=0.07, right=0.97,
hspace=0.3, wspace=0.3)
((ax1, ax2), (ax3, ax4)) = axes # unpack the axes


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
# example, the 'Nearest_vs_none-pdf.pdf' has been pre-converted into
#'Nearest_vs_none-pdf.png' at 80 dpi. We simply need to load and
# display it.
# The conversion is done with:
# gs -dNOPAUSE -dBATCH -dDOINTERPOLATE -sDEVICE=pngalpha \
# -sOutputFile=None_vs_nearest-pdf.png -r80 None_vs_nearest-pdf.pdf
pdf_im_path = cbook.get_sample_data('None_vs_nearest-pdf.png')
pdf_im = plt.imread(pdf_im_path)
fig2 = plt.figure(figsize=[8.0, 7.5])
Expand Down
6 changes: 0 additions & 6 deletions examples/pylab_examples/break.py

This file was deleted.

23 changes: 12 additions & 11 deletions examples/pylab_examples/hexbin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
ymin = y.min()
ymax = y.max()

plt.subplots_adjust(hspace=0.5)
plt.subplot(121)
plt.hexbin(x, y, cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Hexagon binning")
cb = plt.colorbar()
fig, axs = plt.subplots(ncols=2, sharey=True, figsize=(7, 4))
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
ax = axs[0]
hb = ax.hexbin(x, y, gridsize=50, cmap='inferno')
ax.axis([xmin, xmax, ymin, ymax])
ax.set_title("Hexagon binning")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('counts')

plt.subplot(122)
plt.hexbin(x, y, bins='log', cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
ax = axs[1]
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
ax.axis([xmin, xmax, ymin, ymax])
ax.set_title("With a log color scale")
cb = fig.colorbar(hb, ax=ax)
cb.set_label('log10(N)')

plt.show()
29 changes: 17 additions & 12 deletions examples/pylab_examples/image_nonuniform.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
'''
This illustrates the NonUniformImage class, which still needs
an axes method interface; either a separate interface, or a
generalization of imshow.
This illustrates the NonUniformImage class. It is not
available via an Axes method but it is easily added to an
Axes instance as shown here.
'''

from matplotlib.pyplot import figure, show
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import NonUniformImage
from matplotlib import cm

interp = 'nearest'

# Linear x array for cell centers:
x = np.linspace(-4, 4, 9)

# Highly nonlinear x array:
x2 = x**3

y = np.linspace(-4, 4, 9)
#print('Size %d points' % (len(x) * len(y)))

z = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2)

fig = figure()
fig.suptitle('NonUniformImage class')
ax = fig.add_subplot(221)
fig, axs = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(bottom=0.07, hspace=0.3)
fig.suptitle('NonUniformImage class', fontsize='large')
ax = axs[0, 0]
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
cmap=cm.Purples)
im.set_data(x, y, z)
Expand All @@ -28,7 +33,7 @@
ax.set_ylim(-4, 4)
ax.set_title(interp)

ax = fig.add_subplot(222)
ax = axs[0, 1]
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
cmap=cm.Purples)
im.set_data(x2, y, z)
Expand All @@ -39,7 +44,7 @@

interp = 'bilinear'

ax = fig.add_subplot(223)
ax = axs[1, 0]
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
cmap=cm.Purples)
im.set_data(x, y, z)
Expand All @@ -48,7 +53,7 @@
ax.set_ylim(-4, 4)
ax.set_title(interp)

ax = fig.add_subplot(224)
ax = axs[1, 1]
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
cmap=cm.Purples)
im.set_data(x2, y, z)
Expand All @@ -57,4 +62,4 @@
ax.set_ylim(-4, 4)
ax.set_title(interp)

show()
plt.show()
19 changes: 7 additions & 12 deletions examples/pylab_examples/image_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(100.0)
x.shape = (10, 10)
x = np.arange(120)
x.shape = (10, 12)

interp = 'bilinear'
#interp = 'nearest'
lim = -2, 11, -2, 6
plt.subplot(211, facecolor='g')
plt.title('blue should be up')
plt.imshow(x, origin='upper', interpolation=interp)
#plt.axis(lim)
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(3, 5))
axs[0].set_title('blue should be up')
axs[0].imshow(x, origin='upper', interpolation=interp)

plt.subplot(212, facecolor='y')
plt.title('blue should be down')
plt.imshow(x, origin='lower', interpolation=interp)
#plt.axis(lim)
axs[1].set_title('blue should be down')
axs[1].imshow(x, origin='lower', interpolation=interp)
plt.show()
12 changes: 8 additions & 4 deletions examples/scales/scales.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter

np.random.seed(1)
# make up some data in the interval ]0, 1[
y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y > 0) & (y < 1)]
y.sort()
x = np.arange(len(y))

# plot with various axes scales
fig, axs = plt.subplots(2, 2)
fig, axs = plt.subplots(2, 2, sharex=True)
fig.subplots_adjust(left=0.08, right=0.98, wspace=0.3)

# linear
ax = axs[0, 0]
Expand All @@ -30,18 +33,19 @@


# symmetric log
ax = axs[1, 0]
ax = axs[1, 1]
ax.plot(x, y - y.mean())
ax.set_yscale('symlog', linthreshy=0.05)
ax.set_yscale('symlog', linthreshy=0.02)
ax.set_title('symlog')
ax.grid(True)

# logit
ax = axs[1, 1]
ax = axs[1, 0]
ax.plot(x, y)
ax.set_yscale('logit')
ax.set_title('logit')
ax.grid(True)
ax.yaxis.set_minor_formatter(NullFormatter())


plt.show()
4 changes: 2 additions & 2 deletions examples/specialty_plots/hinton_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def hinton(matrix, max_weight=None, ax=None):
ax = ax if ax is not None else plt.gca()

if not max_weight:
max_weight = 2**np.ceil(np.log(np.abs(matrix).max())/np.log(2))
max_weight = 2 ** np.ceil(np.log(np.abs(matrix).max()) / np.log(2))

ax.patch.set_facecolor('gray')
ax.set_aspect('equal', 'box')
Expand All @@ -26,7 +26,7 @@ def hinton(matrix, max_weight=None, ax=None):

for (x, y), w in np.ndenumerate(matrix):
color = 'white' if w > 0 else 'black'
size = np.sqrt(np.abs(w))
size = np.sqrt(np.abs(w) / max_weight)
rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,
facecolor=color, edgecolor=color)
ax.add_patch(rect)
Expand Down
Binary file modified lib/matplotlib/mpl-data/sample_data/None_vs_nearest-pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run(extra_args):
if '--no-network' in sys.argv:
from matplotlib.testing import disable_internet
disable_internet.turn_off_internet()
extra_args.extend(['--eval-attr="not network"'])
extra_args.extend(['-a', '!network'])
sys.argv.remove('--no-network')

run(extra_args)

0 comments on commit a72574d

Please sign in to comment.