Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #GRAPH GENERATION WITH NUMPY
- import matplotlib.pyplot as plt
- from matplotlib.scale import LinearScale
- import numpy as np
- def tempgraph():
- """gen a graph"""
- fig = plt.figure()
- ydata = range(1000)
- yspan = 0.1
- x1data = [20 * np.sin(i * yspan) + 20 for i in ydata]
- x2data = [20 * np.cos(i * yspan) + 20 for i in ydata]
- #create subplots
- ax1 = fig.add_subplot(1, 2, 1)
- ax1.plot(x1data, ydata, 'b-', scalex=False)
- ax2 = fig.add_subplot(1, 2, 2, sharey=ax1, scalex=False)
- ax2.plot(x2data, ydata, 'r-')
- #calculate grid
- #divisions of x axis
- xgrid = {
- 'rang': max(x1data),
- 'maj': 2,
- 'min': 10
- }
- #how many units per grid
- ygrid = {
- 'rang': max(ydata),
- 'maj': int(10 / yspan),
- 'min': int(5 / yspan)
- }
- #set grid and eliminate labels
- for i in [ax1, ax2]:
- plt.setp(i.get_xticklabels(), visible=False)
- plt.setp(i.get_yticklabels(), visible=False)
- i.grid(linewidth=1,
- axis='both',
- alpha=0.3,
- linestyle='-',
- which='both')
- for k in ('min', 'maj'):
- #put x grid
- v = [(t + 1.0) * xgrid['rang'] / (xgrid[k])
- for t in range(xgrid[k] - 1)]
- i.set_xticks(v, minor=(k == 'min'))
- #put y grid
- divs = ygrid['rang'] / ygrid[k]
- if ygrid['rang'] % ygrid[k] != 0:
- divs += 1
- l = [t * ygrid[k] for t in range(divs)]
- i.set_yticks(l, minor=(k == 'min'))
- plt.show()
- plt.savefig('test_graph.pdf')
- if __name__ == '__main__':
- tempgraph()
Advertisement
Add Comment
Please, Sign In to add comment