optional xkcd plot style

This commit is contained in:
2019-12-26 18:49:19 +01:00
parent b5607deecb
commit 6604261978
3 changed files with 46 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from plotstyle import colors, cm_size, show_spines
from plotstyle import colors, cm_size, show_spines, set_xlabel, set_ylabel, bar_fac
if __name__ == "__main__":
# wikipedia:
@@ -21,8 +21,8 @@ if __name__ == "__main__":
ax1 = fig.add_subplot(spec[0, 0])
show_spines(ax1, 'lb')
ax1.scatter(indices, data, c=colors['blue'], edgecolor='white', s=50)
ax1.set_xlabel('index')
ax1.set_ylabel('Weight / kg')
set_xlabel(ax1, 'index')
set_ylabel(ax1, 'Weight', 'kg')
ax1.set_xlim(-10, 310)
ax1.set_ylim(0, 370)
ax1.set_yticks(np.arange(0, 351, 100))
@@ -31,11 +31,11 @@ if __name__ == "__main__":
show_spines(ax2, 'lb')
xx = np.arange(0.0, 350.0, 0.5)
yy = st.norm.pdf(xx, mu, sigma)
ax2.plot(yy, xx, color=colors['red'])
ax2.plot(yy, xx, color=colors['red'], lw=2)
bw = 20.0
h, b = np.histogram(data, np.arange(0, 401, bw))
ax2.barh(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], height=0.9*bw, align='edge')
ax2.set_xlabel('pdf / 1/kg')
ax2.barh(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], height=bar_fac*bw, align='edge')
set_xlabel(ax2, 'pdf', '1/kg')
ax2.set_xlim(0, 0.012)
ax2.set_xticks([0, 0.005, 0.01])
ax2.set_xticklabels(['0', '0.005', '0.01'])

View File

@@ -2,7 +2,7 @@ import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from plotstyle import colors, cm_size, show_spines
from plotstyle import colors, cm_size, show_spines, set_xlabel, set_ylabel, bar_fac
def boltzmann(x, x0, k):
return 1.0/(1.0+np.exp(-k*(x-x0)))
@@ -27,8 +27,8 @@ if __name__ == "__main__":
show_spines(ax1, 'lb')
ax1.plot(xx, yy, colors['red'], lw=2)
ax1.scatter(x, y, c=colors['blue'], edgecolor='white', s=50)
ax1.set_xlabel('Hair deflection / nm')
ax1.set_ylabel('Open probability')
set_xlabel(ax1, 'Hair deflection', 'nm')
set_ylabel(ax1, 'Open probability')
ax1.set_xlim(-20, 20)
ax1.set_ylim(-0.2, 1.17)
ax1.set_xticks(np.arange(-20.0, 21.0, 10.0))
@@ -41,11 +41,11 @@ if __name__ == "__main__":
ax2.plot(xg, yg, colors['red'], lw=2)
bw = 0.05
h, b = np.histogram(y-boltzmann(x, x0, k), np.arange(-1.0, 1.01, bw))
ax2.bar(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], width=0.9*bw, align='edge')
ax2.set_xlabel('residuals')
ax2.set_ylabel('pdf')
ax2.bar(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], width=bar_fac*bw, align='edge')
set_xlabel(ax2, 'residuals', 'nm')
set_ylabel(ax2, 'pdf')
ax2.set_xlim(-0.3, 0.3)
#ax2.set_ylim(0, 370)
ax2.set_ylim(0, 5.05)
#ax2.set_xticks([0, 0.005, 0.01])
#ax2.set_xticklabels(['0', '0.005', '0.01'])
#ax2.set_yticks(np.arange(0, 351, 100))