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

Skip to content

Commit 22222e4

Browse files
mdboomddale
authored andcommitted
Restores files accidentally removed in commit 0e6dad5
1 parent 376df4e commit 22222e4

25 files changed

+978
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import matplotlib.pyplot as plt
2+
import mpl_toolkits.axisartist as axisartist
3+
4+
def setup_axes(fig, rect):
5+
ax = axisartist.Subplot(fig, rect)
6+
fig.add_axes(ax)
7+
8+
ax.set_ylim(-0.1, 1.5)
9+
ax.set_yticks([0, 1])
10+
11+
ax.axis[:].set_visible(False)
12+
13+
ax.axis["x"] = ax.new_floating_axis(1, 0.5)
14+
ax.axis["x"].set_axisline_style("->", size=1.5)
15+
16+
return ax
17+
18+
fig = plt.figure(figsize=(3,2.5))
19+
fig.subplots_adjust(top=0.8)
20+
ax1 = setup_axes(fig, "111")
21+
22+
ax1.axis["x"].set_axis_direction("left")
23+
24+
25+
plt.show()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import matplotlib.pyplot as plt
2+
import mpl_toolkits.axisartist as axisartist
3+
4+
def setup_axes(fig, rect):
5+
ax = axisartist.Subplot(fig, rect)
6+
fig.add_axes(ax)
7+
8+
ax.set_ylim(-0.1, 1.5)
9+
ax.set_yticks([0, 1])
10+
11+
#ax.axis[:].toggle(all=False)
12+
#ax.axis[:].line.set_visible(False)
13+
ax.axis[:].set_visible(False)
14+
15+
ax.axis["x"] = ax.new_floating_axis(1, 0.5)
16+
ax.axis["x"].set_axisline_style("->", size=1.5)
17+
18+
return ax
19+
20+
fig = plt.figure(figsize=(6,2.5))
21+
fig.subplots_adjust(bottom=0.2, top=0.8)
22+
23+
ax1 = setup_axes(fig, "121")
24+
ax1.axis["x"].set_ticklabel_direction("+")
25+
ax1.annotate("ticklabel direction=$+$", (0.5, 0), xycoords="axes fraction",
26+
xytext=(0, -10), textcoords="offset points",
27+
va="top", ha="center")
28+
29+
ax2 = setup_axes(fig, "122")
30+
ax2.axis["x"].set_ticklabel_direction("-")
31+
ax2.annotate("ticklabel direction=$-$", (0.5, 0), xycoords="axes fraction",
32+
xytext=(0, -10), textcoords="offset points",
33+
va="top", ha="center")
34+
35+
36+
plt.show()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import matplotlib.pyplot as plt
2+
import mpl_toolkits.axisartist as axisartist
3+
4+
def setup_axes(fig, rect):
5+
ax = axisartist.Subplot(fig, rect)
6+
fig.add_axes(ax)
7+
8+
ax.set_ylim(-0.1, 1.5)
9+
ax.set_yticks([0, 1])
10+
11+
#ax.axis[:].toggle(all=False)
12+
#ax.axis[:].line.set_visible(False)
13+
ax.axis[:].set_visible(False)
14+
15+
ax.axis["x"] = ax.new_floating_axis(1, 0.5)
16+
ax.axis["x"].set_axisline_style("->", size=1.5)
17+
18+
return ax
19+
20+
fig = plt.figure(figsize=(6,2.5))
21+
fig.subplots_adjust(bottom=0.2, top=0.8)
22+
23+
ax1 = setup_axes(fig, "121")
24+
ax1.axis["x"].label.set_text("Label")
25+
ax1.axis["x"].toggle(ticklabels=False)
26+
ax1.axis["x"].set_axislabel_direction("+")
27+
ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction",
28+
xytext=(0, -10), textcoords="offset points",
29+
va="top", ha="center")
30+
31+
ax2 = setup_axes(fig, "122")
32+
ax2.axis["x"].label.set_text("Label")
33+
ax2.axis["x"].toggle(ticklabels=False)
34+
ax2.axis["x"].set_axislabel_direction("-")
35+
ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction",
36+
xytext=(0, -10), textcoords="offset points",
37+
va="top", ha="center")
38+
39+
40+
plt.show()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import matplotlib.pyplot as plt
2+
import mpl_toolkits.axisartist as axisartist
3+
4+
def setup_axes(fig, rect):
5+
ax = axisartist.Subplot(fig, rect)
6+
fig.add_axes(ax)
7+
8+
ax.set_ylim(-0.1, 1.5)
9+
ax.set_yticks([0, 1])
10+
11+
ax.axis[:].set_visible(False)
12+
13+
ax.axis["x1"] = ax.new_floating_axis(1, 0.3)
14+
ax.axis["x1"].set_axisline_style("->", size=1.5)
15+
16+
ax.axis["x2"] = ax.new_floating_axis(1, 0.7)
17+
ax.axis["x2"].set_axisline_style("->", size=1.5)
18+
19+
return ax
20+
21+
fig = plt.figure(figsize=(6,2.5))
22+
fig.subplots_adjust(bottom=0.2, top=0.8)
23+
24+
ax1 = setup_axes(fig, "121")
25+
ax1.axis["x1"].label.set_text("rotation=0")
26+
ax1.axis["x1"].toggle(ticklabels=False)
27+
28+
ax1.axis["x2"].label.set_text("rotation=10")
29+
ax1.axis["x2"].label.set_rotation(10)
30+
ax1.axis["x2"].toggle(ticklabels=False)
31+
32+
ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction",
33+
xytext=(0, -10), textcoords="offset points",
34+
va="top", ha="center")
35+
36+
ax2 = setup_axes(fig, "122")
37+
38+
ax2.axis["x1"].set_axislabel_direction("-")
39+
ax2.axis["x2"].set_axislabel_direction("-")
40+
41+
ax2.axis["x1"].label.set_text("rotation=0")
42+
ax2.axis["x1"].toggle(ticklabels=False)
43+
44+
ax2.axis["x2"].label.set_text("rotation=10")
45+
ax2.axis["x2"].label.set_rotation(10)
46+
ax2.axis["x2"].toggle(ticklabels=False)
47+
48+
49+
ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction",
50+
xytext=(0, -10), textcoords="offset points",
51+
va="top", ha="center")
52+
53+
54+
plt.show()
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
3+
import numpy as np
4+
import mpl_toolkits.axisartist.angle_helper as angle_helper
5+
import mpl_toolkits.axisartist.grid_finder as grid_finder
6+
from matplotlib.projections import PolarAxes
7+
from matplotlib.transforms import Affine2D
8+
9+
import mpl_toolkits.axisartist as axisartist
10+
11+
from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear
12+
13+
14+
def setup_axes(fig, rect):
15+
"""
16+
polar projection, but in a rectangular box.
17+
"""
18+
19+
# see demo_curvelinear_grid.py for details
20+
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
21+
22+
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
23+
lon_cycle = 360,
24+
lat_cycle = None,
25+
lon_minmax = None,
26+
lat_minmax = (0, np.inf),
27+
)
28+
29+
grid_locator1 = angle_helper.LocatorDMS(12)
30+
grid_locator2 = grid_finder.MaxNLocator(5)
31+
32+
tick_formatter1 = angle_helper.FormatterDMS()
33+
34+
grid_helper = GridHelperCurveLinear(tr,
35+
extreme_finder=extreme_finder,
36+
grid_locator1=grid_locator1,
37+
grid_locator2=grid_locator2,
38+
tick_formatter1=tick_formatter1
39+
)
40+
41+
42+
ax1 = axisartist.Subplot(fig, rect, grid_helper=grid_helper)
43+
ax1.axis[:].toggle(ticklabels=False)
44+
45+
fig.add_subplot(ax1)
46+
47+
ax1.set_aspect(1.)
48+
ax1.set_xlim(-5, 12)
49+
ax1.set_ylim(-5, 10)
50+
51+
#ax1.grid(True)
52+
53+
return ax1
54+
55+
56+
def add_floating_axis1(ax1):
57+
ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 30)
58+
axis.label.set_text(r"$\theta = 30^{\circ}$")
59+
axis.label.set_visible(True)
60+
61+
return axis
62+
63+
64+
def add_floating_axis2(ax1):
65+
ax1.axis["lon"] = axis = ax1.new_floating_axis(1, 6)
66+
axis.label.set_text(r"$r = 6$")
67+
axis.label.set_visible(True)
68+
69+
return axis
70+
71+
72+
import matplotlib.pyplot as plt
73+
fig = plt.figure(1, figsize=(8, 4.))
74+
fig.clf()
75+
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99,
76+
wspace=0.01, hspace=0.01)
77+
78+
for i, d in enumerate(["bottom", "left", "top", "right"]):
79+
ax1 = setup_axes(fig, rect=241++i)
80+
axis = add_floating_axis1(ax1)
81+
axis.set_axis_direction(d)
82+
ax1.annotate(d, (0, 1), (5, -5),
83+
xycoords="axes fraction", textcoords="offset points",
84+
va="top", ha="left")
85+
86+
for i, d in enumerate(["bottom", "left", "top", "right"]):
87+
ax1 = setup_axes(fig, rect=245++i)
88+
axis = add_floating_axis2(ax1)
89+
axis.set_axis_direction(d)
90+
ax1.annotate(d, (0, 1), (5, -5),
91+
xycoords="axes fraction", textcoords="offset points",
92+
va="top", ha="left")
93+
94+
95+
96+
plt.show()
97+
98+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import matplotlib.pyplot as plt
2+
3+
from mpl_toolkits.axes_grid.inset_locator import inset_axes, zoomed_inset_axes
4+
from mpl_toolkits.axes_grid.colorbar import colorbar
5+
6+
def get_demo_image():
7+
from matplotlib.cbook import get_sample_data
8+
import numpy as np
9+
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
10+
z = np.load(f)
11+
# z is a numpy array of 15x15
12+
return z, (-3,4,-4,3)
13+
14+
15+
fig = plt.figure(1, [5,4])
16+
ax = fig.add_subplot(111)
17+
18+
Z, extent = get_demo_image()
19+
20+
ax.set(aspect=1,
21+
xlim=(-15, 15),
22+
ylim=(-20, 5))
23+
24+
25+
axins = zoomed_inset_axes(ax, 2, loc=2) # zoom = 6
26+
im = axins.imshow(Z, extent=extent, interpolation="nearest",
27+
origin="lower")
28+
29+
plt.xticks(visible=False)
30+
plt.yticks(visible=False)
31+
32+
33+
# colorbar
34+
cax = inset_axes(axins,
35+
width="5%", # width = 10% of parent_bbox width
36+
height="100%", # height : 50%
37+
loc=3,
38+
bbox_to_anchor=(1.05, 0., 1, 1),
39+
bbox_transform=axins.transAxes,
40+
borderpad=0,
41+
)
42+
43+
44+
colorbar(im, cax=cax) #, ticks=[1,2,3])
45+
46+
47+
plt.draw()
48+
plt.show()
49+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import matplotlib.pyplot as plt
2+
from mpl_toolkits.axes_grid.axes_divider import make_axes_locatable
3+
4+
from mpl_toolkits.axes_grid.colorbar import colorbar
5+
# from matplotlib.pyplot import colorbar
6+
7+
fig = plt.figure(1, figsize=(6, 3))
8+
fig.subplots_adjust(wspace=0.5)
9+
10+
ax1 = fig.add_subplot(121)
11+
im1 = ax1.imshow([[1,2],[3,4]])
12+
13+
ax1_divider = make_axes_locatable(ax1)
14+
cax1 = ax1_divider.append_axes("right", size="7%", pad="2%")
15+
cb1 = colorbar(im1, cax=cax1)
16+
17+
ax2 = fig.add_subplot(122)
18+
im2 = ax2.imshow([[1,2],[3,4]])
19+
20+
ax2_divider = make_axes_locatable(ax2)
21+
cax2 = ax2_divider.append_axes("top", size="7%", pad="2%")
22+
cb2 = colorbar(im2, cax=cax2, orientation="horizontal")
23+
cax2.xaxis.set_ticks_position("top")
24+
plt.show()
25+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import matplotlib.pyplot as plt
2+
3+
from mpl_toolkits.axes_grid \
4+
import Divider, LocatableAxes, Size
5+
6+
def demo_fixed_size_axes():
7+
8+
fig1 = plt.figure(1, (6, 6))
9+
10+
# The first items are for padding and the second items are for the axes.
11+
# sizes are in inch.
12+
h = [Size.Fixed(1.0), Size.Fixed(4.5)]
13+
v = [Size.Fixed(0.7), Size.Fixed(5.)]
14+
15+
divider = Divider(fig1, (0.0, 0.0, 1., 1.), h, v, aspect=False)
16+
# the width and height of the rectangle is ignored.
17+
18+
ax = LocatableAxes(fig1, divider.get_position())
19+
ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
20+
21+
fig1.add_axes(ax)
22+
23+
ax.plot([1,2,3])
24+
25+
26+
27+
28+
def demo_fixed_pad_axes():
29+
30+
fig = plt.figure(2, (6, 6))
31+
32+
# The first & third items are for padding and the second items are for the axes.
33+
# sizes are in inch.
34+
h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2),]
35+
v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5),]
36+
37+
divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)
38+
# the width and height of the rectangle is ignored.
39+
40+
ax = LocatableAxes(fig, divider.get_position())
41+
ax.set_axes_locator(divider.new_locator(nx=1, ny=1))
42+
43+
fig.add_axes(ax)
44+
45+
ax.plot([1,2,3])
46+
47+
48+
49+
50+
51+
52+
if __name__ == "__main__":
53+
demo_fixed_size_axes()
54+
demo_fixed_pad_axes()
55+
56+
plt.draw()
57+
plt.show()

0 commit comments

Comments
 (0)