我有一个情节
(https://i.stack.imgur.com/OI4Bb.png)
基于matplotlib网站的示例:https://matplotlib.org/stable/gallery/lines_bars_and_markers/barchart.html
但我修改了它以适应我的数据:
import matplotlib.pyplot as plt
import numpy as np
def plot_A2():
fysiker = ("JB", "EG")
volymer_A2 = {
'M4': (22.9, 17.6),
'M5': (22.0, 16.4),
'M6': (21.4, 16.0),
'M7': (21.8, 17.6),
}
x = np.arange(len(fysiker)) # the label locations
width = 0.15 # the width of the bars
multiplier = -0.5
fig, ax = plt.subplots(layout='constrained')
for attribute, measurement in volymer_A2.items():
offset = width * multiplier
rects = ax.bar(x + offset, measurement, width, label=attribute)
ax.bar_label(rects, padding=3)
multiplier += 1
# Plottar sann volym
volume_A2 = 18.77
ax.plot([-2,5], [volume_A2, volume_A2], "k--", linewidth=1, color='gray', label='True volume')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Volume (ml)')
ax.set_title('Phantom A2')
ax.set_xticks(x + width, fysiker)
ax.legend(loc='upper center')
ax.set_ylim(15, 25)
ax.set_xlim(-0.2, 1.5)
#ax.grid()
plt.show()
但是,我希望条的 colored颜色 是灰度级.如果可能的话,用一些模式来区分它们,比如这样的:
(https://i.stack.imgur.com/WGyin.png)
你会怎么做?
感谢你的帮助!