1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
| ax.set_ylabel(u'Temperature (\N{DEGREE SIGN}C)', fontweight='bold')
from mpl_toolkits.axes_grid1 import make_axes_locatable divider = make_axes_locatable(ax1) cax = divider.append_axes("right", size="5%", pad=0.1) cbar = plt.colorbar(cf, cax=cax) cbarlabel = "xxxx" cbar.ax.set_xlabel(cbarlabel,size = 8,labelpad=-35)
cbaxes = fig.add_axes([0.83, 0.125, 0.1, 0.01]) cbar = plt.colorbar(ss,cax=cbaxes,orientation='horizontal') loc_ = np.array([5,10,15,20,25]) cbar.set_ticks(loc_) cbar.set_ticklabels(loc_)
(1) cbar.ax.tick_params(labelsize=8) (2) cbar.ax.set_xticklabels(cbar.ax.get_xticklabels(), fontsize=8) cbar.ax.set_xlabel(r'$\mathregular{OC/EC}$',fontsize = 8,labelpad = -28)
from matplotlib.font_manager import FontProperties mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] plt.rcParams['axes.unicode_minus'] = False
def stylize_axes(ax): ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.xaxis.set_tick_params(top='off', direction='out', width=1) ax.yaxis.set_tick_params(right='off', direction='out', width=1)
from scipy import stats slope, intercept, r_value, p_value, slope_std_error = stats.linregress(x, y) xx = np.arange(x.min(),x,max(),0.01) yy = slope*xx+intercept clabel = plt.plot(xx,yy,color ='k', lw =1.2, linestyle = "-", label = clabel)
def get_aspect(ax): xlim = ax.get_xlim() ylim = ax.get_ylim() aspect_ratio = abs((ylim[0]-ylim[1]) / (xlim[0]-xlim[1])) return aspect_ratio fig = plt.figure(figsize=(12,8)) ax1=plt.subplot(121, projection=ccrs.PlateCarree()) ax2=plt.subplot(122) ax2.set_aspect(get_aspect(ax1) / get_aspect(ax2))
for area in [100, 300, 500]: plt.scatter([], [], c='k', alpha=0.3, s=area, label=str(area) + ' km$^2$') plt.legend(scatterpoints=1, frameon=False, labelspacing=1, title='City Area')
ax.tick_params(axis=u'both', which=u'both',length=0)
fig = plt.figure(figsize=(7,4))
left, width = 0.07, 0.6 bottom, height = 0.1, .8 bottom_h = left_h = left+width+0.05 rect_cones = [left, bottom, width, height] rect_box = [left_h, bottom, 0.5, height] ax1 = plt.axes(rect_cones,projection=ccrs.PlateCarree()) ax2 = plt.axes(rect_box) ax2.set_aspect(get_aspect(ax1) / get_aspect(ax2))
def plot_legend(title): s = [1,3,5,7,9] c = plt.cm.binary(np.arange(5)/5.0) labels =['A',"B",'C',"D","E"] cir1 = plt.scatter([1], [2], c=c[0], alpha=0.8, s=s[0],label=r'<0.5') cir2 = plt.scatter([1], [2], c=c[1], alpha=0.8, s=s[1],label=labels[1]) cir3 = plt.scatter([1], [2], c=c[2], alpha=0.8, s=s[2],label=labels[2]) cir4 = plt.scatter([1], [2], c=c[3], alpha=0.8, s=s[3],label=labels[3]) cir5 = plt.scatter([1], [2], c=c[4], alpha=0.8, s=s[4],label=labels[4]) leg = plt.legend([cir1,cir2,cir3,cir4,cir5],labels,scatterpoints = 1, \ frameon=False, labelspacing=0.9, ncol =2, fontsize=8,title=title , loc = [0.05,0.1])
c_list = plt.cm.rainbow(np.arange(6)/6.0)
axu = ax.twinx() axu.spines["right"].set_position(("axes", 1.25)) so_,=plt.plot(xxx) axu.yaxis.label.set_color(so_.get_color()) axu.spines['right'].set_color(so_.get_color()) axu.spines["right"].set_edgecolor(so_.get_color()) axu.tick_params(axis='y', colors=so_.get_color())
from matplotlib.patches import Rectangle import matplotlib.patches as mpatches rec = mpatches.Rectangle((position[i]- width/2.0,bot_[i]),width,hei_[i],linewidth=1,edgecolor='b',facecolor='none',zorder=12) ax.add_patch(rec)
def make_rgb_transparent(rgb, bg_rgb, alpha): return [alpha * c1 + (1 - alpha) * c2 for (c1, c2) in zip(rgb, bg_rgb)] from matplotlib import colors import matplotlib.pyplot as plt
alpha = 0.5
kwargs = dict(edgecolors='none', s=3900, marker='s') for i, color in enumerate(['red', 'blue', 'green']): rgb = colors.colorConverter.to_rgb(color) rgb_new = make_rgb_transparent(rgb, (1, 1, 1), alpha) print(color, rgb, rgb_new) plt.scatter([i], [0], color=color, **kwargs) plt.scatter([i], [1], color=color, alpha=alpha, **kwargs) plt.scatter([i], [2], color=rgb_new, **kwargs)
def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100): new_cmap = colors.LinearSegmentedColormap.from_list( 'trunc({n},{a:.2f},{b:.2f})'.format(n=cmap.name, a=minval, b=maxval), cmap(np.linspace(minval, maxval, n))) return new_cmap cmap = plt.get_cmap('terrain') terrain_cmap = truncate_colormap(cmap, 0.15, 0.9)
import matplotlib.gridspec as gridspec fig = plt.figure(figsize=(9,6)) gs = gridspec.GridSpec(46,1) row_xx = 23
ax1 = plt.subplot(gs[0:row_xx, 0])
lines, labels = ax.get_legend_handles_labels() lines2, labels2 = ax2.get_legend_handles_labels() ax2.legend(lines + lines2, labels + labels2, loc=0)
ax.set_xticks([0, 60, 120, 180, 240, 300, 360], crs=ccrs.PlateCarree()) ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree()) lon_formatter = LongitudeFormatter(zero_direction_label=True) lat_formatter = LatitudeFormatter() ax.xaxis.set_major_formatter(lon_formatter) ax.yaxis.set_major_formatter(lat_formatter)
ax.set_xticks(np.arange(extent[0]+2, extent[1]+2, 15), crs=ccrs.PlateCarree()) ax.set_yticks(np.arange(extent[2]+3, extent[3], 15), crs=ccrs.PlateCarree()) ax.set_xticklabels([r'$\mathrm{75^o E}$',r'$\mathrm{90^o E}$',r'$\mathrm{105^o E}$',\ r'$\mathrm{120^o E}$',r'$\mathrm{135^o E}$',]) ax.set_yticklabels([r'$\mathrm{20^o N}$',r'$\mathrm{35^o N}$',r'$\mathrm{50^o N}$'])
from matplotlib.axes import Axes from cartopy.mpl.geoaxes import GeoAxes GeoAxes._pcolormesh_patched = Axes.pcolormesh
import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties
song_ti = FontProperties(fname=r'/Library/Fonts/Songti.ttc', size=20) times_new_roman = FontProperties(fname=r'/Library/Fonts/Arial Black.ttf', size=15) ax = plt.gca() ax.set_title(u'能量随时间的变化', fontproperties=song_ti) ax.set_xlabel('Time (s)', fontproperties=times_new_roman) ax.set_ylabel('Energy (J)', fontproperties=times_new_roman) plt.show()
(label='_nolegend_')
ax.set_facecolor("#F5F5F5")
import matplotlib.colors as colors
class MidpointNormalize(colors.Normalize): def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False): self.midpoint = midpoint colors.Normalize.__init__(self, vmin, vmax, clip)
def __call__(self, value, clip=None): x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1] return np.ma.masked_array(np.interp(value, x, y))
cbaxes = fig.add_axes([0.29, 0.27, 0.18, 0.02]) cbar = plt.colorbar(ss,cax=cbaxes, orientation='horizontal') n = 6 st_po = [] for i in range(0,n,1): st_po.append(np.array_split(pd.to_datetime(sorted(date_point)),n)[i].values[0]) cb_ticks = [float(c) for c in st_po] cbar.ax.set_xticklabels(pd.to_datetime(cb_ticks).strftime('%b')) cbar.ax.tick_params(labelsize=8.5)
import nclcmaps nclcmaps.cmaps("precip2_17lev")
cm = LinearSegmentedColormap.from_list('test',plt.cm.BuPu(np.arange(6)/6.0)[1:], N=5)
http://chris35wills.github.io/discrete_colourbar/
from matplotlib.ticker import StrMethodFormatter, NullFormatter ax.yaxis.set_major_formatter(StrMethodFormatter('{x:.3f}')) ax.yaxis.set_minor_formatter(NullFormatter())
fig, axs = plt.subplots(2,4, figsize=(15, 6), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.001) axs = axs.ravel()
for i in range(8):
axs[i].contourf(np.random.rand(10,10),5,cmap=plt.cm.Oranges) axs[i].set_title(str(250+i))
from matplotlib.collections import PatchCollection from matplotlib.patches import Rectangle def PATCH_BOX(ax,pos,wid): for x in pos[::2]: width = wid/2.0 facecolor = "#F0F0F0" rect = Rectangle((x-width, 0.00), width*4.0,1000000,facecolor=facecolor,linewidth = 0) ax.add_patch(rect)
https://github.com/SciTools/cartopy/issues/837 pip uninstall shapely && pip install --no-binary :all: shapely
pip uninstall shapely & pip install shapely --no-binary shapely==1.7a2
linewidths=1
from matplotlib import cm cs=cm.Set2(np.arange(4)/4.)
ax.plot(0.3,-0.1 , 'ro', fillstyle='full', markersize=5, transform=ax.transAxes,clip_on =False)
|
Kommentare