forked from gizmaa/Julia_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyplot_brokenAxisSubplot.jl
61 lines (50 loc) · 1.81 KB
/
pyplot_brokenAxisSubplot.jl
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
# pyplot_brokenAxisSubplot.jl
#
# Demonstrate use of broken axis subplot
#
# Ian Butterworth (https://gist.github.com/ianshmean)
# Julia 1.1.0
# 13.05.2019
# Last Edit: 13.05.2019
# Reference: https://gist.github.com/gizmaa/7214002#gistcomment-2831191
using PyPlot, PyCall
axes_grid1 = pyimport("mpl_toolkits.axes_grid1")
###################
## Create Data ##
###################
x = rand(100)
y = rand(100)
y2 = rand(100).+10
##########################
## First (Upper) Plot ##
##########################
fig = figure("pyplot_brokenAxisSubplot",figsize=(10,10))
axes = fig.subplots(nrows=2, sharex=true)
ax = axes[1]
divider = axes_grid1.make_axes_locatable(ax)
ax2 = divider.new_vertical(size="100%", pad=0.1)
fig.add_axes(ax2)
# Lower Portion of First Plot
ax.scatter(x, y)
ax.set_ylim(0, 1)
ax.spines["top"].set_visible(false)
# Upper Portion of First Plot
ax2.scatter(x, y2)
ax2.set_ylim(10, 11)
ax2.tick_params(bottom="off", labelbottom="off")
ax2.spines["bottom"].set_visible(false)
###############################
## Add Line Break Markings ##
###############################
# From https://matplotlib.org/examples/pylab_examples/broken_axis.html
# Upper Line Break Markings
d = 0.015 # how big to make the diagonal lines in axes coordinates
ax2.plot((-d, +d), (-d, +d), transform=ax2.transAxes, color="k", clip_on=false,linewidth=0.8) # Left diagonal
ax2.plot((1 - d, 1 + d), (-d, +d), transform=ax2.transAxes, color="k", clip_on=false,linewidth=0.8) # Right diagonal
# Lower Line Break Markings
ax.plot((-d, +d), (1 - d, 1 + d), transform=ax.transAxes, color="k", clip_on=false,linewidth=0.8) # Left diagonal
ax.plot((1 - d, 1 + d), (1 - d, 1 + d), transform=ax.transAxes, color="k", clip_on=false,linewidth=0.8) # Right diagonal
###################
## Second Plot ##
###################
axes[2].scatter(x, y)