作家
登录

5使用Python代码轻松实现数据可视化的方法

作者: 来源: 2018-03-26 15:24:38 阅读 我要评论

这里是折线图的代码。它和膳绫擎的散点图很类似,只是在一些变量上有小的变更。

  1. def lineplot(x_data, y_data, x_label="", y_label="", title=""): 
  2.     # Create the plot object  
  3.     _, ax = plt.subplots()    # Plot the best fit line, set the linewidth (lw), color and  
  4.     # transparency (alpha) of the line 
  5.     ax.plot(x_data, y_data, lw = 2, color = '#539caf', alpha = 1)    # Label the axes and provide a title  
  6.     ax.set_title(title)  
  7.     ax.set_xlabel(x_label)  
  8.     ax.set_ylabel(y_label)  
  1. # Overlay 2 histograms to compare themdef overlaid_histogram(data1, data2, n_bins = 0, data1_name="", data1_color="#539caf", data2_name="", data2_color="#7663b0", x_label="", y_label="", title=""):  
  2.     # Set the bounds for the bins so that the two distributions are fairly compared  
  3.     max_nbins = 10  
  4.     data_range = [min(min(data1), min(data2)), max(max(data1), max(data2))]  
  5.     binwidth = (data_range[1] - data_range[0]) / max_nbins    if n_bins == 0  
  6.         bins = np.arange(data_range[0], data_range[1] + binwidth, binwidth)    else 
  7.         bins = n_bins    # Create the plot  
  8.     _, ax = plt.subplots()  
  9.     ax.hist(data1, bins = bins, color = data1_color, alpha = 1, label = data1_name)  
  10.     ax.hist(data2, bins = bins, color = data2_color, alpha = 0.75, label = data2_name) 

      推荐阅读

      HTTPS那些协议:TLS, SSL, SNI, ALPN, NPN

    沙龙晃荡 | 3月31日 京东、微博、华为拭魅战专家与你合营商量容器技巧实践! 本文存眷个中 Web 办事(HTTPS)相干>>>详细阅读


    本文标题:5使用Python代码轻松实现数据可视化的方法

    地址:http://www.17bianji.com/lsqh/40891.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)