私はBirtを使って棒グラフを作成しましたが、技術の変更によりMatplotlibを使用する必要があります。 Matplotlibを使用して同様のチャートを作成することが可能かどうか(そして、どのようにして)、特に棒グラフの上部80%を囲む範囲が、例えばmatplotlibを使用して棒グラフに範囲の破線のボックスを追加すると暑いですか?
であるかを知りたいと思います。
私はそれを作成する方法に関するドキュメントは見つかりませんでした。
誰かが進行する方法を知っていますか?
私はBirtを使って棒グラフを作成しましたが、技術の変更によりMatplotlibを使用する必要があります。 Matplotlibを使用して同様のチャートを作成することが可能かどうか(そして、どのようにして)、特に棒グラフの上部80%を囲む範囲が、例えばmatplotlibを使用して棒グラフに範囲の破線のボックスを追加すると暑いですか?
であるかを知りたいと思います。
私はそれを作成する方法に関するドキュメントは見つかりませんでした。
誰かが進行する方法を知っていますか?
このようなものです。
破線のボックスにはmatplotlib.patches.Rectangle
を使用できます。
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
import matplotlib.ticker as ticker
# Fake some data
x = np.array([15,25,35,45,45,45,45,45,75,75,95,150,160,170,170,1040])
y = np.arange(0.1,16.1,1)
percent = np.array([(100.*float(i)/x.sum()) for i in x])
# Create Figure and Axes
fig,ax = plt.subplots(1)
# Plot the bars
ax.barh(y,x)
# Move left and bottom spines outward by 5 points
ax.spines['left'].set_position(('outward', 5))
ax.spines['bottom'].set_position(('outward', 5))
# Hide the right and top spines
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Only show ticks on the left and bottom spines
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
# Set the axes limits and tick locations
ax.set_ylim(0,16)
ax.set_yticklabels([])
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
ax.set_xlim(0,1100)
ax.xaxis.set_major_locator(ticker.MultipleLocator(100))
# Add the rectangle
rect = Rectangle((0,10), 1100, 6, linestyle = 'dashed', facecolor = 'None', clip_on=False)
ax.add_patch(rect)
# Add the percentage labels
for p,xi,yi in zip(percent,x,y):
ax.text(xi+5,yi+0.2,'{:2.0f}\%'.format(p))
plt.show()
よろしくお願いします。tomさん、どうもありがとうございました。 Rectangleの幅と高さが実際の軸スケールを参照していることはわかりませんでした。 – 29axe
デフォルトの 'transform'を使用しています。これは' ax.transData'です。変換を 'ax.transAxes'に変更した場合、分数軸の座標を使用することができます。例えば、以下のようになります:' rect = Rectangle((0,0.625)、1、0.375、linestyle = 'dashed'、facecolor = 'None'、clip_on = False、transform = ax.transAxes) 'は上記と同じボックスを返す – tom
ないあなたがここに後にしているものをかなり確実に一致するように外側に
spines
を移動しました。プロットに四角形を追加するだけの場合は、[API](http://matplotlib.org/api/artist_api.html#matplotlib.patches.Rectangle)といくつかの[examples](http://matplotlib.org /examples/shapes_and_collections/artist_reference.html)。 – iayorkページ上に図形を描くだけでなく、プロット上のデータの80%、この例では人口の82%の周囲にボックスを自動的に生成することです。レポートを読んでいる人が、ほとんどのデータがどこにあるのかが明確に分かります。これはBirtの "MarkerRangeImpl"に相当します。 – 29axe