简体   繁体   English

具有 2 种颜色或渐变的颜色 matplotlib 补丁

[英]color matplotlib patch with 2 colors or a gradient

I need to coloring an Ellipse with two different colors.我需要用两种不同的颜色为椭圆着色。 This could be done half and half or better, an horizontal gradient.这可以一半一半或更好地完成,水平渐变。

I would like to keep using matplotlib patches and not to use equations to draw the ellipse.我想继续使用 matplotlib 补丁而不是使用方程来绘制椭圆。

I'm using this minimal code to point the problem.我正在使用这个最少的代码来指出问题。

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()

Anserws to How to draw a filled arc in matplotlib are directed to fill a circle arc except for one that can fill a ellipse arc. 如何在 matplotlib绘制填充圆弧的答案旨在填充圆弧,但可以填充椭圆弧的圆弧除外。

This is a cartoon of what I need这是我需要的漫画

在此处输入图片说明

The patch arc can draw a semi ellipse, but by default it can not be filled.面片圆弧可以画半椭圆,但默认是不能填充的。

I found how to fill and arc in: How to draw a filled arc in matplotlib .我找到了如何填充和圆弧: 如何在 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'))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM