python - 使用误差线图旋转 matplotlib 标记
问题描述
我遵循这个答案来旋转预先存在的 matplotlib 标记。
但是,那里的解决方案不适用于误差线图。这是一个简单的example.py
:
#!/usr/bin/env python3
import matplotlib.pyplot as plt
from matplotlib.markers import MarkerStyle
# I want to use this marker in an errorbar plot
m = MarkerStyle("D")
m._transform.scale(1.0, 0.6)
# I can use it in a scatter plot
fig, 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 errorbar
fix, 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
#> Path(marker)
#> File "/usr/local/lib/python3.8/site-packages/matplotlib/path.py", line 127, in __init__
#> vertices = _to_unmasked_float_array(vertices)
#> File "/usr/local/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 1317, in _to_unmasked_float_array
#> return np.asarray(x, float)
#> File "/usr/local/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
#> return array(a, dtype, copy=False, order=order)
#>TypeError: float() argument must be a string or a number, not 'MarkerStyle'
问:如何在误差线图中使用旋转的预先存在的 matplotlib 标记(或者,可能是任何 MarkerStyle 标记)? (真的我想要 90˚ 旋转thin_diamond
。)
解决方案
推荐阅读
- ios - 我可以使用 ARKit 和 ARSK View 更改锚点或移动图像吗?
- android - 隐藏设备是模拟器的事实?
- jquery - 完整日历中的资源组字段在角度 4 中不起作用
- python - 在二进制字段中使用“ir.attachment”——odoo
- android - 我应该使用哪个密钥来签署要上传到 GooglePlay 的 Android 应用程序的谷歌地图
- spring-batch - 如何获取 MultiResourceItemReader 读取的文件/资源的数量,即 Resource[] 的长度?
- ios - swift无法转换类型的值
- asp.net-mvc - RowVersion 值未绑定在表单数据中,mvc 5
- matplotlib - 条形与值不成比例 - matplotlib 条形图
- linux - 在每个版本上下载 Yocto zip