Movatterモバイル変換


[0]ホーム

URL:


  1. matplotlib-gallery
  2. ipynb
Notebook

Sebastian Raschka

back to thematplotlib-gallery athttps://github.com/rasbt/matplotlib-gallery

In [1]:
%load_ext watermark
In [2]:
%watermark -u -v -d -p matplotlib,numpy
Last updated: 07/10/2015 CPython 3.4.3IPython 3.2.0matplotlib 1.4.3numpy 1.9.2

In [3]:
%matplotlib inline


Matplotlib Formatting III: What it takes to become a legend

I won't be a rock star. I will be a legend.

--Freddie Mercury



Sections



Back to square one

In [6]:
importmatplotlib.pyplotaspltimportnumpyasnpx=np.arange(10)foriinrange(1,4):plt.plot(x,i*x**2,label='Group%d'%i)plt.legend(loc='best')plt.show()


Let's get fancy

In [7]:
x=np.arange(10)foriinrange(1,4):plt.plot(x,i*x**2,label='Group%d'%i)plt.legend(loc='best',fancybox=True,shadow=True)plt.show()


Thinking outside the box

In [8]:
fig=plt.figure()ax=plt.subplot(111)x=np.arange(10)foriinrange(1,4):ax.plot(x,i*x**2,label='Group%d'%i)ax.legend(loc='upper center',bbox_to_anchor=(0.5,# horizontal1.15),# verticalncol=3,fancybox=True)plt.show()
In [22]:
fig=plt.figure()ax=plt.subplot(111)x=np.arange(10)foriinrange(1,4):ax.plot(x,i*x**2,label='Group%d'%i)ax.legend(loc='upper center',bbox_to_anchor=(1.15,1.02),ncol=1,fancybox=True)plt.show()


I love when things are transparent, free and clear

In [27]:
x=np.arange(10)foriinrange(1,4):plt.plot(x,i*x**2,label='Group%d'%i)plt.legend(loc='upper right',framealpha=0.1)plt.show()


Markers -- All good things come in threes!

In [32]:
fromitertoolsimportcyclex=np.arange(10)colors=['blue','red','green']color_gen=cycle(colors)foriinrange(1,4):plt.scatter(x,i*x**2,label='Group%d'%i,color=next(color_gen))plt.legend(loc='upper left')plt.show()
In [35]:
fromitertoolsimportcyclex=np.arange(10)colors=['blue','red','green']color_gen=cycle(colors)foriinrange(1,4):plt.scatter(x,i*x**2,label='Group%d'%i,color=next(color_gen))plt.legend(loc='upper left',scatterpoints=1)plt.show()
In [37]:
fromitertoolsimportcyclex=np.arange(10)colors=['blue','red','green']color_gen=cycle(colors)foriinrange(1,4):plt.plot(x,i*x**2,label='Group%d'%i,marker='o')plt.legend(loc='upper left')plt.show()
In [38]:
fromitertoolsimportcyclex=np.arange(10)colors=['blue','red','green']color_gen=cycle(colors)foriinrange(1,4):plt.plot(x,i*x**2,label='Group%d'%i,marker='o')plt.legend(loc='upper left',numpoints=1)plt.show()
In [ ]:

[8]ページ先頭

©2009-2025 Movatter.jp