我在Python中使用matplotlib,并制作了一个带条的直方图。现在,当直方图出现时,只有5的倍数出现在x轴上,1000的倍数出现在y轴上。对于y轴,这是完全没有问题的,但是对于x轴,我希望间隔是1而不是5,因为我每小时使用1巴。我如何才能做到这一点?
提前谢谢。
def plotHistogramTickets():
hours_NumbersSold = dict()
for i in range(24):
hours_NumbersSold[i]=0
soldTickets = db.getSoldTickets()
for tic
我试图用matplotlib绘制一个简单的直方图。例如,我将在实践中使用不同的距离函数。
import matplotlib.pyplot as plt
import numpy as np
import itertools
def hamdist(str1, str2):
"""Count the # of differences between equal length strings str1 and str2"""
if (len(str1) != len(str2)):
print str1, str
我通常不使用Matplotlib,我试图在时间序列直方图中绘制一些信息。
当我把数据放进去时,我的直方图工作得很好,但我无法得到它来显示X轴勾标。
下面是我的代码(使用占位符数据):
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.dates import HourLocator as HourLocater
import datetime
from datetime import datetime
from datetime import timedelt
我画了如下指数分布的直方图。如何在此直方图的顶部添加拟合线。
from scipy.stats import expon
import matplotlib.pyplot as plt
data_expon = expon.rvs(size=1000,scale=1,loc=0)
# the histogram of the data
plt.hist(data_expon, 100, density=True, facecolor='r', alpha=0.75)
plt.xlabel('exponential')
plt.ylabel('PDF
我有一本字典d
d = {'apples': 5, 'oranges': 2, 'bananas': 2, 'lemons': 1, 'coconuts': 1}
如何以图形方式显示它,作为使用(pylab/matplotlib/ pandas/what-ever-is-best-suitable-for-simple-histograms)的直方图
我正在寻找的是对以下内容的图形类推:
X
X
X
X X X
X X X X X
-------------
A O B L C
我有一个散点图,上面有x-axis的时间
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import ticker
d = ({
'A' : ['08:00:00','08:10:00','08:12:00','08:26:00','08:29:00','08:31:00','10:10:00','10:25:00','10:29:00'
我有一个带有ts_array时间戳的数组,它遵循dd-mm-yyyy格式,比如03-08-2012。现在,我想用matplotlib 1.5.1和Python 2.7绘制一个直方图如下:
import matplotlib.pyplot as plt
timestamps = dict((x, ts_array.count(x)) for x in ts_array)
plt.hist(timestamps)
plt.title("Timestamp Histogram")
plt.xlabel("Value")
plt.ylabel("Freque
我试图使用Matplotlib的gridspec创建子图,即直方图上方的框图。我有熊猫的数量数据。我有这样的代码:
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(20, 20))
outer = fig.add_gridspec(6, 2, wspace=0.05, hspace=0.2)
a = 0
for i in range(6):
for j in range(2):
我正在尝试创建一个分组盒图,表示具有不同大小的多个发行版。这些大小应该显示在顶部的直方图中。
我现在的代码是:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import numpy.random as rnd
some_x=[1,2,3,7,9,10,11,12,15,18]
x_appearances=[]
data_for_each_x=[]
for i in range(0, len(some_x)):
rand_int=rnd.randint(10,30)
data