Matplotlib demos! Single, animated, multiple
This commit is contained in:
parent
82e326a6c1
commit
e1637fe8c8
3 changed files with 326 additions and 12 deletions
|
@ -41,18 +41,66 @@ def draw_figure(canvas, figure, loc=(0, 0)):
|
|||
return photo
|
||||
|
||||
#------------------------------- PASTE YOUR MATPLOTLIB CODE HERE -------------------------------
|
||||
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from matplotlib.ticker import NullFormatter # useful for `logit` scale
|
||||
|
||||
# Fixing random state for reproducibility
|
||||
np.random.seed(19680801)
|
||||
|
||||
# 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))
|
||||
|
||||
matplotlib.rcParams['axes.unicode_minus'] = False
|
||||
fig, ax = plt.subplots()
|
||||
ax.plot(10*np.random.randn(100), 10*np.random.randn(100), 'o')
|
||||
ax.set_title('Using hyphen instead of Unicode minus')
|
||||
# plot with various axes scales
|
||||
plt.figure(1)
|
||||
|
||||
# linear
|
||||
plt.subplot(221)
|
||||
plt.plot(x, y)
|
||||
plt.yscale('linear')
|
||||
plt.title('linear')
|
||||
plt.grid(True)
|
||||
|
||||
|
||||
# log
|
||||
plt.subplot(222)
|
||||
plt.plot(x, y)
|
||||
plt.yscale('log')
|
||||
plt.title('log')
|
||||
plt.grid(True)
|
||||
|
||||
|
||||
# symmetric log
|
||||
plt.subplot(223)
|
||||
plt.plot(x, y - y.mean())
|
||||
plt.yscale('symlog', linthreshy=0.01)
|
||||
plt.title('symlog')
|
||||
plt.grid(True)
|
||||
|
||||
# logit
|
||||
plt.subplot(224)
|
||||
plt.plot(x, y)
|
||||
plt.yscale('logit')
|
||||
plt.title('logit')
|
||||
plt.grid(True)
|
||||
# Format the minor tick labels of the y-axis into empty strings with
|
||||
# `NullFormatter`, to avoid cumbering the axis with too many labels.
|
||||
plt.gca().yaxis.set_minor_formatter(NullFormatter())
|
||||
# Adjust the subplot layout, because the logit one may take more space
|
||||
# than usual, due to y-tick labels like "1 - 10^{-3}"
|
||||
plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
|
||||
wspace=0.35)
|
||||
|
||||
|
||||
#------------------------------- END OF YOUR MATPLOTLIB CODE -------------------------------
|
||||
|
||||
# ****** Comment out this line if not using Pyplot ******
|
||||
fig = plt.gcf() # if using Pyplot then get the figure from the plot
|
||||
|
||||
# -------------------------------- GUI Starts Here -------------------------------#
|
||||
# fig = your figure you want to display. Assumption is that 'fig' holds the #
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue