【问题标题】:color matplotlib patch with 2 colors or a gradient具有 2 种颜色或渐变的颜色 matplotlib 补丁
【发布时间】:2017-06-27 17:22:41
【问题描述】:

我需要用两种不同的颜色为椭圆着色。这可以做到一半一半或更好,水平渐变。

我想继续使用 matplotlib 补丁,而不是使用方程式来绘制椭圆。

我正在使用这个最小的代码来指出问题。

import matplotlib.pyplot as plt
import matplotlib.patches as mpatch

ax = plt.subplot(111)
ax.add_patch(mpatch.Ellipse(xy = [0.5, 0.5], width= 0.75, height=0.5, facecolor = 'blue'))
plt.show()

How to draw a filled arc in matplotlib 的答案被定向为填充圆弧,但可以填充椭圆弧的答案除外。

这是我需要的漫画

【问题讨论】:

标签: python matplotlib colors


【解决方案1】:

补丁圆弧可以画一个半椭圆,但默认不能填充。

我找到了如何填充和弧线: How to draw a filled arc in matplotlib.

import matplotlib.pyplot as plt
import matplotlib.patches as mpatch

ax = plt.subplot(111)
ax.add_patch(mpatch.Arc(xy = [0.5, 0.5], width= 0.75, height=0.5, angle=.0, theta1= 90.0, theta2=-90.0, color = 'blue', hatch = 'OOOO'))
ax.add_patch(mpatch.Arc(xy = [0.5, 0.5], width= 0.75, height=0.5, angle=.0, theta1=-90.0, theta2= 90.0, color = 'green', hatch = 'OOOO'))

【讨论】:

  • 此解决方案取决于图像分辨率,如果有足够的缩放,则可以注意到点而不是纯色。
猜你喜欢
  • 1970-01-01
  • 2019-12-07
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-12
相关资源
最近更新 更多