python matplotlib绘制散点图(Pythonmatplotlibmatplotlib绘制)
Python matplotlib:使用matplotlib绘制--柱状图和折线图的组合。
废话不多说,直接上效果图和代码。
代码如下:
#柱状图
import numpy as np
import matplotlib.pyplot as plt
C1 = '#99CCFF'
#C2 = '#CCFFFF'
C2 = '#CCCCFF'
C3 = "#6699CC"
AAA = [227.74,165.24,146.42]
BBB = [234.78,188.48,158.94]
CCC = [284.83,200.33,162.23]
#CNN_RLSTM = [0.9016,0.8636,0.9435]
#x = ['REST','LAPT','AUTO']
x = np.arange(3) #总共有几组,就设置成几,我们这里有三组,所以设置为3
total_width, n = 0.8, 3 # 有多少个类型,只需更改n即可,比如这里我们对比了四个,那么
#就把n设成4
width = total_width / n
x = x - (total_width - width) / 2
'''
#plt.bar用于绘制柱状图
plt.bar(x, AAA, color = C2,width=width,label='AAA ') ###或者color C2可以换成默认
plt.bar(x width, BBB, color = C1,width=width,label='BBB')
plt.bar(x 2 * width, CCC , color = C3,width=width,label='CCC')
'''
###或者color C2可以换成默认
plt.bar(x, AAA, color = 'r',width=width,label='AAA ') ###或者color C2可以换成默认
plt.bar(x width, BBB, color = 'y',width=width,label='BBB')
plt.bar(x 2 * width, CCC , color = 'k',width=width,label='CCC')
#plt.bar(x 3 * width, CNN_RLSTM , color = "g",width=width,label='CNN-RLSTM')
plt.xlabel("LUT")
plt.ylabel("Energy(KWh)")
plt.legend(loc = "best")
plt.xticks([0,1,2],['0.1','0.2','0.3'])
my_y_ticks = np.arange(120, 300, 50)
plt.ylim((150, 300))
plt.yticks(my_y_ticks)
AAA_plot = [2*0.16325,2* 0.13622, 2*0.11936]
BBB_plot = [2*0.1752, 2*0.14554,2*0.13491]
CCC_plot = [2*0.15599, 2*0.15473, 2*0.1956]
ax2 = plt.twinx() # 用于绘制双Y轴,重点。
'''
ax2.plot(x width, AAA_plot, color=C2)
ax2.plot(x width, BBB_plot, color=C1)
ax2.plot(x width, CCC_plot, color=C3)
'''
# 折线也可换颜色
ax2.plot(x width, AAA_plot, color='r')
ax2.plot(x width, BBB_plot, color='y')
ax2.plot(x width, CCC_plot, color='k')
ax2.set_ylim([0, 0.4])
my_y_ticks = np.arange(0, 0.4, 0.1)
plt.ylim((0, 0.4))
plt.yticks(my_y_ticks)
plt.show()
# 大功告成,谢谢观看。
喜欢点击关注、收藏。么么哒(^_^)
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com