python - Matplotlib Rectangle With Color Gradient Fill -


I want to make a rectangle, together with a gradient color from left to right, with my arbitrary an arbitrary manner In case the axis example ( ax1 ) coordinate system.

Enter image details here

My first thought was Create a path patch and somehow set your fill as a color gradient. But there is no way to do this accordingly.

Next I tried to use a color palette I used the ax2 fig.ed_xs ([left, bottom, width, height]) > Created and added a color bar for it

  ax2 = fig.add_axes ([0, 0, width, height / 8]) color = [grad_start_color, grad_end_color] index = [0.0, 1.0] cm = Linear Segment Colormap.from_list ('my_colormap', zip (index, color)) colorbar.ColorbarBase (ax2, cmap = cms, orientation = 'horizontal')  
< P> but positional paragraph Itr FIG. is in the coordinate system of Fig , and the coordinate system of ax1 does not match.

How can I do this?

Thanks for any help.

Have you ever solved this? I wanted to do the same thing and wanted to use the coordinate mapping from Ape, #Map axis to coordinate system def metodtocores (ax, dat_cord): tr1 = ax.trans.data. Transform (dat_coord) # To make the inversion change from the design to make the coordinates: fig = ax.get_figure () inv = fig.transFigure.inverted () tr2 = inv.transform (tr1) # left, bottom, width, height as follows Is obtained: datco = [tr2 [0,0], tr2 [0,1], tr2 [1,0] -tr2 [0,0], tr2 [1,1] -tr2 [0,1]] Return Date #P A colorful (Ax, X, Y, W, H, C, ** quarj) inside a new axis def curve with the dot: xa, or, wa, ha = exponentators (ax, [x, y], ( X + y, y + h))] fig = ax.get_figure () axnew = fig.add_axes ([xa, ya, wa, ha]) cp ​​= mpl.colorbar.colorbarbase (axnew, cmap = plt. Get_cmap ("red"), orientation = 'vertical', ticks = [], ** kwargs) cp.outline.set_linewidt H (0). Plt.sca (hope)

Hope this helps anyone in the future to have the same functionality. I am using a grid of patch objects.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -