python用matplotlib画折线图

折线图:
import matplotlib.pyplot as plt&#xA0;<br>y1=[10,13,5,40,30,60,70,12,55,25]&#xA0;<br>x1=range(0,10)&#xA0;<br>x2=range(0,10)&#xA0;<br>y2=[5,8,0,30,20,40,50,10,40,15]&#xA0;<br>plt.plot(x1,y1,label='Frist line',linewidth=3,color='r',marker='o',&#xA0;<br>markerfacecolor='blue',markersize=12)&#xA0;<br>plt.plot(x2,y2,label='second line')&#xA0;<br>plt.xlabel('Plot Number')&#xA0;<br>plt.ylabel('Important var')&#xA0;<br>plt.title('Interesting Graph\nCheck it out')&#xA0;<br>plt.legend()&#xA0;<br>plt.show()&#xA0;<br>

python用matplotlib画折线图

条形图

import matplotlib.pyplot as plt
y1=[<span class="hljs-number">10,<span class="hljs-number">13,<span class="hljs-number">5,<span class="hljs-number">40,<span class="hljs-number">30,<span class="hljs-number">60,<span class="hljs-number">70,<span class="hljs-number">12,<span class="hljs-number">55,<span class="hljs-number">25]
x1=<span class="hljs-keyword">range(<span class="hljs-number">0,<span class="hljs-number">20,<span class="hljs-number">2)
x2=<span class="hljs-keyword">range(<span class="hljs-number">1,<span class="hljs-number">21,<span class="hljs-number">2)
y2=[<span class="hljs-number">5,<span class="hljs-number">8,<span class="hljs-number">0,<span class="hljs-number">30,<span class="hljs-number">20,<span class="hljs-number">40,<span class="hljs-number">50,<span class="hljs-number">10,<span class="hljs-number">40,<span class="hljs-number">15]
plt.bar(x1,y1,<span class="hljs-keyword">label=<span class="hljs-attribute">'Frist line')
#plt.bar(x2,y2,<span class="hljs-keyword">label=<span class="hljs-attribute">'second line',color=<span class="hljs-attribute">'r')
plt.xlabel(<span class="hljs-attribute">'Plot Number')
plt.ylabel(<span class="hljs-attribute">'Important var')
plt.title(<span class="hljs-attribute">'Interesting Graph\nCheck it <span class="hljs-keyword">out')
plt.legend()
plt.show()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

python用matplotlib画折线图

直方图:

<span class="hljs-keyword">import matplotlib.pyplot <span class="hljs-keyword">as plt
population_ages = [<span class="hljs-number">22,<span class="hljs-number">55,<span class="hljs-number">62,<span class="hljs-number">45,<span class="hljs-number">21,<span class="hljs-number">22,<span class="hljs-number">34,<span class="hljs-number">42,<span class="hljs-number">42,<span class="hljs-number">4,<span class="hljs-number">99,<span class="hljs-number">102,
                   <span class="hljs-number">110,<span class="hljs-number">120,<span class="hljs-number">121,<span class="hljs-number">122,<span class="hljs-number">130,<span class="hljs-number">111,<span class="hljs-number">115,<span class="hljs-number">112,<span class="hljs-number">80,<span class="hljs-number">75,
                   <span class="hljs-number">65,<span class="hljs-number">54,<span class="hljs-number">44,<span class="hljs-number">43,<span class="hljs-number">42,<span class="hljs-number">48]
x=range(<span class="hljs-number">0,<span class="hljs-number">130,<span class="hljs-number">10)
plt.hist(population_ages,x,rwidth=<span class="hljs-number">0.8,color=<span class="hljs-string">'r',histtype=<span class="hljs-string">'stepfilled')

plt.xlabel(<span class="hljs-string">'Plot Number')
plt.ylabel(<span class="hljs-string">'Important var')
plt.title(<span class="hljs-string">'Interesting Graph\nCheck it out')
plt.legend()
plt.show()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

python用matplotlib画折线图

散点图:

import matplotlib.pyplot as plt
population_ages = [<span class="hljs-number">22,<span class="hljs-number">55,<span class="hljs-number">62,<span class="hljs-number">45,<span class="hljs-number">21,<span class="hljs-number">22,<span class="hljs-number">34,<span class="hljs-number">42,<span class="hljs-number">42,<span class="hljs-number">4,<span class="hljs-number">99,<span class="hljs-number">102,
                   <span class="hljs-number">110,<span class="hljs-number">120,<span class="hljs-number">121,<span class="hljs-number">122,<span class="hljs-number">130,<span class="hljs-number">111,<span class="hljs-number">115,<span class="hljs-number">112,<span class="hljs-number">80,<span class="hljs-number">75,
                   <span class="hljs-number">65,<span class="hljs-number">54,<span class="hljs-number">44,<span class="hljs-number">43,<span class="hljs-number">42,<span class="hljs-number">48]
x=<span class="hljs-keyword">range(<span class="hljs-number">0,len(population_ages))
plt.scatter(x,population_ages,<span class="hljs-keyword">label=<span class="hljs-attribute">'frist <span class="hljs-keyword">label',s=<span class="hljs-number">20)
help(plt.scatter)
plt.xlabel(<span class="hljs-literal">'x')
plt.ylabel(<span class="hljs-attribute">'y')
plt.title(<span class="hljs-attribute">'Interesting Graph\nCheck it <span class="hljs-keyword">out')
plt.legend()
plt.show()</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

python用matplotlib画折线图

Original: https://www.cnblogs.com/to-creat/p/8134424.html
Author: Wei_java
Title: python用matplotlib画折线图

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/10788/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部