I want to do this Graph (Graph with Vertical Gradient and Ticker Axis values with Background Color):
Graph with Vertical Gradient and Ticker Axis values with Background Color
At this moment I can do this:
My problems now are:
- I have a Gradient but I don't know how to change to orange color, and I don't know how to change gradient values.
My Code is:
import matplotlib.pyplot as plt
from matplotlib.offsetbox import (OffsetImage,AnnotationBbox)
from matplotlib.cbook import get_sample_data
import matplotlib.transforms as transforms
from matplotlib.ticker import (MultipleLocator)
import numpy as np
import matplotlib as mpl
# Control of lines appears in graphic
mpl.rcParams['axes.spines.left'] = True
mpl.rcParams['axes.spines.right'] = True
mpl.rcParams['axes.spines.top'] = False
mpl.rcParams['axes.spines.bottom'] = False
# Sample Data to Show
# create some sample data
x=[0,0,1, 2, 3, 4, 5, 6,7]
y=[0,4,1, 8, 20, 6, 7, 4,0]
fig, ax = plt.subplots()
# Set values of axis
ax.set_xlim(0,max(x))
ax.set_ylim(0,max(y))
# Set color and font size of X Axis
ax.tick_params(axis='x', colors='white')
# Create a transform in Axis VAlues
trans = transforms.blended_transform_factory(ax.transAxes, ax.transAxes)
# Create Rectanagles in percentage of Axis VAlues, and set order
ax.add_patch(plt.Rectangle((-0.04,-0.1),1.08, 0.12,facecolor='black',clip_on=False,linewidth = 0,zorder=1,transform=trans))
ax.add_patch(plt.Rectangle((1.05,-0.1),0.1, 0.12,facecolor='silver',clip_on=False,linewidth = 0,zorder=5,transform=trans))
ax.text(1.06, -0.07, max(x), fontsize = 12,zorder = 6, color = 'k',transform=trans)
# Put pictos in axis
xy = (1, 1)
with get_sample_data(r"C:\Roberto\Visual_Studio_Code\GisBike\pruebas\Grafica\meta.png") as file:
arr_img = plt.imread(file, format='png')
imagebox = OffsetImage(arr_img, zoom=0.2)
imagebox.image.axes = ax
ab = AnnotationBbox(imagebox, xy, xybox=(1, 1.05), xycoords='data', boxcoords=("axes fraction", "axes fraction"), pad=0.5,frameon=False)
ax.add_artist(ab)
with get_sample_data(r"C:\Roberto\Visual_Studio_Code\GisBike\pruebas\Grafica\sortida.png") as file:
arr_img = plt.imread(file, format='png')
imagebox = OffsetImage(arr_img, zoom=0.2)
imagebox.image.axes = ax
ab = AnnotationBbox(imagebox, xy, xybox=(0, 1.05), xycoords='data', boxcoords=("axes fraction", "axes fraction"), pad=0,frameon=False)
ax.add_artist(ab)
with get_sample_data(r"C:\Roberto\Visual_Studio_Code\GisBike\pruebas\Grafica\sortida.png") as file:
arr_img = plt.imread(file, format='png')
imagebox = OffsetImage(arr_img, zoom=0.2)
imagebox.image.axes = ax
ab = AnnotationBbox(imagebox, xy, xybox=(0.5, 1.05), xycoords='data', boxcoords=("axes fraction", "axes fraction"), pad=0,frameon=False,
arrowprops=dict(arrowstyle="-",connectionstyle="angle")) # ,angleA=90
ax.add_artist(ab)
# plot only the outline of the polygon, and capture the result
poly, = ax.fill(x, y, facecolor='none')
# get the extent of the axes
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
# create a dummy image
img_data = np.arange(xmin,xmax,(xmax-xmin)/100.)
img_data = np.arange(ymin,ymax,(ymax-ymin)/100.)
img_data = img_data.reshape(img_data.size,1)
# plot and clip the image
im = ax.imshow(img_data, aspect='auto', origin='upper', cmap=plt.cm.Reds_r, extent=[xmin,xmax,ymin,ymax], zorder=0)
im.set_clip_path(poly)
plt.show()