莫烦-matplotlib学习笔记(三)

来源:互联网 发布:linux统计目录文件数 编辑:程序博客网 时间:2024/05/17 08:16
参考莫烦教学视频:https://morvanzhou.github.io/tutorials/data-manipulation/plt/2-4-axis2/ 
与matplotlib学习笔记(二)http://blog.csdn.net/weixin_39881922/article/details/78493400 中内容类似
import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-3, 3, 50)y1 = 2*x + 1y2 = x**2plt.figure()plt.plot(x, y2)# plot the second curve in this figure with certain parametersplt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')# set x limitsplt.xlim((-1, 2))plt.ylim((-2, 3))# set new ticksnew_ticks = np.linspace(-1, 2, 5)plt.xticks(new_ticks)# set tick labelsplt.yticks([-2, -1.8, -1, 1.22, 3],           ['$really\ bad$', '$bad$', '$normal$', '$good$', '$really\ good$'])# to use '$ $' for math text and nice looking, e.g. '$\pi$'# gca = 'get current axis'ax = plt.gca()ax.spines['right'].set_color('none')ax.spines['top'].set_color('none')ax.xaxis.set_ticks_position('bottom')# ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' | 'none' ]ax.spines['bottom'].set_position(('data', 0))# the 1st is in 'outward' | 'axes' | 'data'# axes: percentage of y axis# data: depend on y dataax.yaxis.set_ticks_position('left')# ACCEPTS: [ 'left' | 'right' | 'both' | 'default' | 'none' ]ax.spines['left'].set_position(('data',0))plt.show()
原创粉丝点击