create a colorful label image for plt to annotate :param label_colors: label color list :param rows: num of figure rows :param cols: num of figure cols :param row_height: height of each row :param col_width: width of each col :return: """label_map=np.ones((row_height*rows,col_wi...
# Import dataset import numpy as np import pandas as pd from matplotlib import pyplot as plt midwest = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/midwest_filter.csv") # Prepare Data # Create as many colors as there are unique midwest['category'] categories = n...
https://matplotlib.org/stable/gallery/color/named_colors.html
完整代码: import numpy as npimport matplotlib as mplimport matplotlib.pyplot as plt# from colorspacious import cspace_convertercmaps = {}gradient = np.linspace(0, 1, 256)gradient = np.vstack((gradient, gradient))def plot_color_gradients(category, cmap_list):# Create figure and adjust figure...
read_csv("data/midwest_filter.csv") """ Prepare Data """ """ Create as many colors as there are unique midwest['category'] """ categories = np.unique(midwest['category']) colors = [plt.cm.tab10(i / float(len(categories) - 1)) for i in range(len(categories))] """ Draw ...
[25, 40, 35, 30] # Custom color list for the colormap (e.g., shades of blue, green, red, and purple) custom_colors = ['#1f77b4', '#2ca02c', '#d62728', '#9467bd'] # Create a ListedColormap using the custom colors custom_cmap = ListedColormap(custom_colors) # Set the...
rects2 = plt.bar([i+0.4foriinx], height=num_list2, width=0.4, color='green', label='部门二')# 设置y轴属性plt.ylim(0,50) plt.ylabel('数量')# 设置x轴属性plt.xticks([index+0.2forindexinx], label_list) plt.xlabel("年份") ...
ax.errorbar(x_data,y_data,yerr=error_data,color='#297083',ls='none',lw=2,capthick=2)ax.set_ylabel(y_label)ax.set_xlabel(x_label)ax.set_title(title)defstackedbarplot(x_data,y_data_list,colors,y_data_names="",x_label="",y_label="",title=""):_,ax=plt.subplots()# Draw ba...
for style_label in style_list: with plt.style.context(style_label): fig = plot_figure(style_label=style_label) plt.show() 两个接口 有两种不同的方式使用MatPlotLib: 第一种是MATLAB风格 第二种是面向对象的界面风格 MATLAB风格 plt.figure() # create a plot figure x = np.linspace(0, 10, ...
plt.scatter(x, y, c=colors)plt.show() Result: Try it Yourself » ColorMapThe Matplotlib module has a number of available colormaps.A colormap is like a list of colors, where each color has a value that ranges from 0 to 100.Here is an example of a colormap:This...