我是靠谱客的博主 虚幻热狗,最近开发中收集的这篇文章主要介绍python数据可视化之matplotlib精进,Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章...,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

图 5.1

c11d3390389a4db4163d892b88c2db7f.png

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

importmatplotlib.pyplot as pltimportnumpy as npfrom matplotlib.ticker importAutoMinorLocator, MultipleLocator, FuncFormatter

x=np.linspace(0.5, 3.5, 100)

y=np.sin(x)

fig=plt.figure(figsize=(8, 8))

ax=fig.add_subplot(111)

ax.xaxis.set_major_locator(MultipleLocator(1.0))

ax.yaxis.set_major_locator(MultipleLocator(1.0))

ax.xaxis.set_minor_locator(AutoMinorLocator(4))

ax.yaxis.set_minor_locator(AutoMinorLocator(4))defminor_tick(x, pos):if not x%1.0:return ""

return "%.2f"%x

ax.xaxis.set_minor_formatter(FuncFormatter(minor_tick))

ax.tick_params("y", which='major',length=15, width=2.0, colors='r')

ax.tick_params(which='minor', length=5, width=1.0, labelsize=10, labelcolor='0.25')

ax.set_xlim(0,4)

ax.set_ylim(0,2)

ax.plot(x, y, c=(0.25, 0.25, 1.00), lw=2, zorder=10)#ax.plot(x, y, c=(0.25, 0.25, 1.00), lw=2, zorder=0)

ax.grid(linestyle='-', linewidth=0.5, color='r', zorder=0)#ax.grid(linestyle='-', linewidth=0.5, color='r', zorder=10)#ax.grid(linestyle='--', linewidth=0.5, color='0.25', zorder=0)

plt.show()

View Code

-------------------------------------------------------------------------------------

图 5.2

ba27af57da62a31663640709f65f45e9.png

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

importmatplotlib.pyplot as pltimportnumpy as np

fig=plt.figure(facecolor=(1.0, 1.0, 0.9412))

ax=fig.add_axes([0.1, 0.4, 0.5, 0.5])for ticklabel inax.xaxis.get_ticklabels():

ticklabel.set_color("slateblue")

ticklabel.set_fontsize(18)

ticklabel.set_rotation(30)for ticklabel inax.yaxis.get_ticklabels():

ticklabel.set_color("lightgreen")

ticklabel.set_fontsize(20)

ticklabel.set_rotation(2)

plt.show()

View Code

-------------------------------------------------------------------------------------

图 5.3

c74e4aaf2099a0258259ecd3a34f5751.png

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

importmatplotlib.pyplot as pltimportnumpy as npfrom calendar importmonth_name, day_namefrom matplotlib.ticker importFormatStrFormatter

fig=plt.figure()

ax=fig.add_axes([0.2, 0.2, 0.7, 0.7])

x=np.arange(1, 8, 1)

y=2*x

ax.plot(x, y, ls='-', lw=2, color='orange', marker='o',

ms=20, mfc='c', mec='r')

ax.yaxis.set_major_formatter(FormatStrFormatter(r"$yen%1.1f$"))

plt.xticks(x, day_name[0:7], rotation=20)

ax.set_xlim(0,8)

ax.set_ylim(0,18)

plt.show()

View Code

-------------------------------------------------------------------------------------

图 5.4

4301447c74d485bf20e00ddada358e41.png

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

importmatplotlib.pyplot as pltimportnumpy as np

x=np.linspace(0.5, 3.5, 100)

y=np.sin(x)

fig=plt.figure(figsize=(8, 8))

ax=fig.add_subplot(111)

ax.plot(x, y, c='b', ls='-', lw=2)

ax.annotate("maximum", xy=(np.pi/2, 1.0), xycoords='data',

xytext=((np.pi/2)+0.15, 0.8), textcoords="data",

weight="bold", color='r',

arrowprops=dict(arrowstyle='->', connectionstyle='arc3', color='r'))

ax.text(2.8, 0.4, "$y=sin(x)$", fontsize=20, color='b',

bbox=dict(facecolor='y', alpha=0.5))

plt.show()

View Code

-------------------------------------------------------------------------------------

图 5.5

来源:oschina

链接:https://my.oschina.net/u/4389867/blog/4288097

最后

以上就是虚幻热狗为你收集整理的python数据可视化之matplotlib精进,Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章...的全部内容,希望文章能够帮你解决python数据可视化之matplotlib精进,Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部