python中使用plt.bar画出的图横坐标是1-10的,我如何画出2,4,6,8这样空两个的横坐标
importmatplotlib.pyplotaspltclassmy_charts:defdrawX_Y(temp):name_list=temp.keys()num_...
import matplotlib.pyplot as plt
class my_charts:
def drawX_Y(temp):
name_list = temp.keys()
num_list = temp.values()
rects = plt.bar(range(len(num_list)), num_list, 0.1, color='rgby')
index = name_list
plt.ylim(ymax=80, ymin=0)
plt.xticks(range(len(name_list)), name_list)
plt.ylabel("account")
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2,height, str(height), ha='center', va='bottom')
plt.show()
temp = {"1":3,"2":2,"3":0,"4":1,"5":7,"6":4,"7":1,"8":3,"9":2,"10":0,"11":1,"12":7}
my_charts.drawX_Y(temp) 展开
class my_charts:
def drawX_Y(temp):
name_list = temp.keys()
num_list = temp.values()
rects = plt.bar(range(len(num_list)), num_list, 0.1, color='rgby')
index = name_list
plt.ylim(ymax=80, ymin=0)
plt.xticks(range(len(name_list)), name_list)
plt.ylabel("account")
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2,height, str(height), ha='center', va='bottom')
plt.show()
temp = {"1":3,"2":2,"3":0,"4":1,"5":7,"6":4,"7":1,"8":3,"9":2,"10":0,"11":1,"12":7}
my_charts.drawX_Y(temp) 展开
2018-09-23 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
关注
展开全部
最简单的柱状代码应该是这样的
# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randint(0, 10, size=10)
y = np.random.randint(100, 1000, size=10)
plt.bar(x, y)
plt.show()
# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randint(0, 10, size=10)
y = np.random.randint(100, 1000, size=10)
plt.bar(x, y)
plt.show()
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询