Last active
July 2, 2016 04:21
-
-
Save yichao0319/416cd1427605be7719f1992d2b12f3bc to your computer and use it in GitHub Desktop.
python:plot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib | |
| matplotlib.use('Agg') | |
| import matplotlib.pyplot as plt | |
| # marker [ '+' | ',' | '.' | '1' | '2' | '3' | '4' ] | |
| # linestyle or ls [ '-' | '--' | '-.' | ':' | 'steps' | ...] | |
| fig_idx = 0 | |
| font_size = 10 | |
| fig_idx += 1 | |
| fig = plt.figure(fig_idx) | |
| plt.clf() | |
| matplotlib.rcParams.update({'font.size': font_size}) | |
| plt.gca().set_color_cycle(['r', 'b', 'g', 'y', 'm']) | |
| for x in xrange(h*w): | |
| lhs = [] | |
| legends = [] | |
| ax = fig.add_subplot(h, w, x+1) | |
| for li in xrange(10): | |
| lh, = plt.plot(x[li], y[li], 'b-') | |
| plt.setp(lh, color='r', linewidth=2.0, \ | |
| marker='o', markerfacecolor='r', \ | |
| fillstyle='full', ms=5, \ | |
| markeredgecolor='red', markeredgewidth=0.0) | |
| lhs.append(lh) | |
| legends.append("line%d" % (li)) | |
| ## TEXT | |
| ax_xlim = ax.get_xlim() | |
| ax_ylim = ax.get_ylim() | |
| xx = ax_xlim[0] + (ax_xlim[1]-ax_xlim[0])*4/10 | |
| yy = ax_ylim[0] + (ax_ylim[1]-ax_ylim[0])*8/10 | |
| ax.text(xx, yy, r'$\mu=100,\ \sigma=15$', style='italic', | |
| bbox={'facecolor':'red', 'alpha':0.5, 'pad':10}, | |
| verticalalignment='bottom', horizontalalignment='right', | |
| transform=ax.transAxes, | |
| color='green', fontsize=15) | |
| ## Annotation | |
| ax.annotate('annotate', xy=(2, 1), xytext=(3, 4), | |
| arrowprops=dict(facecolor='black', shrink=0.05)) | |
| ## TICK | |
| plt.tick_params( | |
| axis='x', # changes apply to the x-axis | |
| which='both', # both major and minor ticks are affected | |
| bottom='off', # ticks along the bottom edge are off | |
| top='off', # ticks along the top edge are off | |
| labelbottom='off') # labels along the bottom edge are off | |
| plt.tick_params( | |
| axis='y', # changes apply to the x-axis | |
| which='both', # both major and minor ticks are affected | |
| bottom='off', # ticks along the bottom edge are off | |
| top='off', # ticks along the top edge are off | |
| labelleft='off') # labels along the bottom edge are off | |
| plt.axis([XMIN,XMAX, YMIN,YMAX]) | |
| ## equals to: | |
| # plt.xlim((XMIN,XMAX)) | |
| # plt.ylim((YMIN,YMAX)) | |
| plt.title('TITLE') | |
| plt.xlabel('XLABEL') | |
| plt.ylabel('YLABEL') | |
| # ax.set_title('TITLE') | |
| # ax.set_xlabel('XLABEL') | |
| # ax.set_ylabel('YLABEL') | |
| plt.grid(True) | |
| fig.legend(lhs, legends, ncol=5, loc='upper center', | |
| bbox_to_anchor=[0.5, 1.1], | |
| columnspacing=1.0, labelspacing=0.0, | |
| handletextpad=0.0, handlelength=1.5, | |
| fancybox=True, shadow=True) | |
| plt.savefig("FILENAME", format='eps', dpi=1000) | |
| plt.show() | |
| ################ | |
| rects1 = ax.bar(x, y, width, color='r', yerr=std) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment