![]() ![]() # But this is only meant as an illustration of a side-plot, so who cares ? # And now the histogram # Use the gridspec magic to place it # - ax1v = plt. set_label ( r'Colorbar !', labelpad = 10 ) # NOTE: I guess that a kernel density plot on top of the histogram would be better from a scientific standpoint. # - cb = Colorbar ( ax = cbax, mappable = plt1, orientation = 'horizontal', ticklocation = 'top' ) cb. subplot ( gs ) # Place it where it should be. set_ylabel ( r'My y label' ) # and let us not forget the colorbar above ! # - cbax = plt. set_xticklabels () # Force this empty ! ax1. linspace ( - 4, 4, 9 )) # Force this to what I want - for consistency with histogram below ! ax1. set_xlabel ( r' ' ) # Force this empty ! ax1. scatter ( x, y, c = z, marker = 's', s = 20, edgecolor = 'none', alpha = 1, cmap = 'magma_r', vmin = 0, vmax = 4 ) # Define the limits, labels, ticks as required ax1. subplot ( gs ) # place it where it should be. # First, the scatter plot # Use the gridspec magic to place it # - ax1 = plt. # So, I insert a 4th layer between the histogram and line plot, # keep it empty, and use its thickness (the 0.2 above) to adjust the space as required. # However, I want to have the histogram 'closer' from the scatter plot than the line plot. So, in principle, I could use a 3x3 structure. I only have three vertical layers of plots : # a scatter plot, a histogram, and a line plot. # BUT: this is irrelevant for the saved image, if using bbox_inches='tight'in savefig ! # Note: Here, I use a little trick. update ( left = 0.05, right = 0.95, bottom = 0.08, top = 0.93, wspace = 0.02, hspace = 0.03 ) # Note: I set the margins to make it look good on my screen. # Also make sure the margins and spacing are apropriate gs. ![]() GridSpec ( 3, 4, height_ratios =, width_ratios = ) # 3 rows, 4 columns, each with the required size ratios. figure ( 1, figsize = ( 15, 8 )) # Now, create the gridspec structure, as required gs = gridspec. , dn)``, filled # with random floats sampled from a univariate "normal" (Gaussian) # distribution of mean 0 and variance 1. sqrt ( x ** 2 + y ** 2 ) # `randn` generates an array of shape ``(d0, d1. Import matplotlib.pyplot as plt # Gives access to basic plotting functions import idspec as gridspec # GRIDSPEC ! from lorbar import Colorbar # For dealing with Colorbars the proper way - TBD in a separate Påoffee ? # Ok, let us start by creating some fake data x = np. Import numpy as np # For creating some fake data # Use some notebook magic - forget the next line in normal scripted code % matplotlib inline set_label ( r'Colorbar !', labelpad = 10 ) fig. ![]() ![]() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |