matplotlib.pyplot
生成的。
import pandas as pd
import matplotlib.pyplot as plt
data = pd.DataFrame(dict(min=[10, 20],
max=[50, 60],
point1=[40, 50],
point2=[30, 40]),
index=["Series 1", "Series 2"])
plt.barh(range(len(data)), data["max"]-data["min"], height=0.3, left=data["min"])
plt.plot(data["point1"], range(len(data)), linestyle="", markersize=10,
marker="o", color="#ff6600", label="Point 1", markeredgecolor="k")
plt.plot(data["point2"], range(len(data)), linestyle="", markersize=10,
marker="o", color="#aa0000", label="Point 2", markeredgecolor="k")
plt.yticks(range(len(data)),data.index)
plt.ylim(-1,3)
plt.xlim(0,80)
plt.legend()
plt.show()
align = "center"
手动将条形图居中。 - ImportanceOfBeingErnestmatplotlib
进行任何绘图。import numpy as np
import matplotlib.pyplot as plt
# make a bar floating in space
index_labels = data.index
index = np.arange(index_labels)
right_edge = data['max']
left_edge = data['min']
plt.barh(index, right_edge, left=left_edge)
plt.yticks(index, index_labels)
这应该生成一个水平条形图,您需要指定条的起点和终点。您可以在此处参考文档:http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.barh并查看示例:http://matplotlib.org/1.2.1/examples/pylab_examples/barh_demo.html。
from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle, Circle
fig = plt.figure()
ax = fig.add_subplot(111, xlim=(0, 70), ylim=(0, 70))
ax.add_artist(Rectangle(xy=(10, 49), color="g", width=40, height=2))
ax.add_artist(Circle(xy=(30, 50), color="orange", radius=1))
ax.add_artist(Circle(xy=(40, 50), color="red", radius=1))
ax.add_artist(Rectangle(xy=(20, 19), color="b", width=40, height=2))
ax.add_artist(Circle(xy=(40, 20), color="orange", radius=1))
ax.add_artist(Circle(xy=(50, 20), color="red", radius=1))
plt.show()