python中使用plt.bar画出的图横坐标是1-10的,我如何画出2,4,6,8这样空两个的横坐标
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python中使用plt.bar画出的图横坐标是1-10的,我如何画出2,4,6,8这样空两个的横坐标相关的知识,希望对你有一定的参考价值。
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)
# 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() 参考技术B 加一句plt.xticks(x)
以上是关于python中使用plt.bar画出的图横坐标是1-10的,我如何画出2,4,6,8这样空两个的横坐标的主要内容,如果未能解决你的问题,请参考以下文章