我正在遵循這個答案來旋轉(zhuǎn)預(yù)先存在的 matplotlib 標(biāo)記。但是,那里的解決方案不適用于誤差條圖。這是一個簡單的example.py:#!/usr/bin/env python3import matplotlib.pyplot as pltfrom matplotlib.markers import MarkerStyle# I want to use this marker in an errorbar plotm = MarkerStyle("D")m._transform.scale(1.0, 0.6)# I can use it in a scatter plotfig, ax = plt.subplots()plt.scatter([1,2,3],[1,2,3], s=225, marker="d")plt.scatter([1,2,3],[2,3,4], s=225, marker=m, color="crimson")plt.show()# which produces a figure similar to https://stackoverflow.com/a/49662571/# But when I use it in errorbarfix, ax = plt.subplots()plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker=m, color='green')plt.show()# I get#>Traceback (most recent call last):#> File "./example.py", line 19, in <module>#> plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker=m, color='green')#> File "/usr/local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2524, in errorbar#> return gca().errorbar(#> File "/usr/local/lib/python3.8/site-packages/matplotlib/__init__.py", line 1565, in inner#> return func(ax, *map(sanitize_sequence, args), **kwargs)#> File "/usr/local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 3265, in errorbar#> data_line = mlines.Line2D(x, y, **plot_line_style)#> File "/usr/local/lib/python3.8/site-packages/matplotlib/lines.py", line 378, in __init__#> self._marker = MarkerStyle(marker, fillstyle)#> File "/usr/local/lib/python3.8/site-packages/matplotlib/markers.py", line 225, in __init__#> self.set_marker(marker)#> File "/usr/local/lib/python3.8/site-packages/matplotlib/markers.py", line 289, in set_marker問:如何在誤差條圖中使用旋轉(zhuǎn)的預(yù)先存在的 matplotlib 標(biāo)記(或者可能是任何 MarkerStyle 標(biāo)記)? (我真的想要 90° 旋轉(zhuǎn)thin_diamond。)
2 回答

慕碼人8056858
TA貢獻(xiàn)1803條經(jīng)驗 獲得超6個贊
有趣的是,我不知道為什么要這樣設(shè)計。解決方法是繪制單獨的散點圖:
fix, ax = plt.subplots()
plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker=None, color='green')
plt.scatter([1,2,3],[3,4,5], s=225, marker=m, color="green")
plt.show()
輸出:

精慕HU
TA貢獻(xiàn)1845條經(jīng)驗 獲得超8個贊
事實證明這是兩個錯誤。PR #16692中修復(fù)了一個問題,該問題已合并到 matplotlib 3.3.0 中(我使用的是 3.2.2)。?另一個我必須修復(fù),將在 3.4.0 中修復(fù)。如果您現(xiàn)在需要此功能,您可能需要matplotlib/markers.py
根據(jù)此 diff來修補您的功能。
添加回答
舉報
0/150
提交
取消