python图案填充_Python:使用matplotlib颜色和图案填充字典
fill_betweenx()
.
我成功地使用了如下示例中的列表。然而,我正在努力找出我可以用類似的方式使用字典。其目的是詞典第一部分中的數字與dataframe中的一列相關,當我來繪制數據時,它應該從詞典中查找相關的hatch和color參數。
實現這一目標的最佳方法是什么?
下面是一個示例字典,我想用它來代替列表
example_dict = {1:{'lith':'sandstone', 'hatch':'.', 'color':'yellow'},
2:{'lith':'fine sand', 'hatch':'..', 'color':'yellow'},
3:{'lith':'mudstone', 'hatch':'-', 'color':'green'},
4:{'lith':'laminated shale', 'hatch':'--', 'color':'green'}}
使用列表的工作代碼。
import matplotlib.pyplot as plt
y = [0, 1]
x = [1, 1]
fig, axes = plt.subplots(ncols=4,nrows=1, sharex=True, sharey=True,
figsize=(10,5), subplot_kw={'xticks': [], 'yticks': []})
colors = ['yellow', 'yellow', 'green', 'green']
hatchings = ['.', '..', '-', '--']
for ax, color, hatch in zip(axes.flat, colors, hatchings):
ax.plot(x, y)
ax.fill_betweenx(y, 0, 1, facecolor=color, hatch=hatch)
ax.set_xlim(0, 0.1)
ax.set_ylim(0, 1)
ax.set_title(str(hatch))
plt.tight_layout()
plt.show()
總結
以上是生活随笔為你收集整理的python图案填充_Python:使用matplotlib颜色和图案填充字典的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为u8860 V100R001CHN
- 下一篇: JavaScript---解决单击、双击