Created
April 14, 2019 19:30
-
-
Save drazenz/992745f004ea344b028e6888021704f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plot_grid = plt.GridSpec(1, 15, hspace=0.2, wspace=0.1) # Setup a 1x15 grid | |
| ax = plt.subplot(plot_grid[:,:-1]) # Use the leftmost 14 columns of the grid for the main plot | |
| ax.scatter( | |
| x=x.map(x_to_num), # Use mapping for x | |
| y=y.map(y_to_num), # Use mapping for y | |
| s=size * size_scale, # Vector of square sizes, proportional to size parameter | |
| c=color.apply(value_to_color), # Vector of square colors, mapped to color palette | |
| marker='s' # Use square as scatterplot marker | |
| ) | |
| # ... | |
| # Add color legend on the right side of the plot | |
| ax = plt.subplot(plot_grid[:,-1]) # Use the rightmost column of the plot | |
| col_x = [0]*len(palette) # Fixed x coordinate for the bars | |
| bar_y=np.linspace(color_min, color_max, n_colors) # y coordinates for each of the n_colors bars | |
| bar_height = bar_y[1] - bar_y[0] | |
| ax.barh( | |
| y=bar_y, | |
| width=[5]*len(palette), # Make bars 5 units wide | |
| left=col_x, # Make bars start at 0 | |
| height=bar_height, | |
| color=palette, | |
| linewidth=0 | |
| ) | |
| ax.set_xlim(1, 2) # Bars are going from 0 to 5, so lets crop the plot somewhere in the middle | |
| ax.grid(False) # Hide grid | |
| ax.set_facecolor('white') # Make background white | |
| ax.set_xticks([]) # Remove horizontal ticks | |
| ax.set_yticks(np.linspace(min(bar_y), max(bar_y), 3)) # Show vertical ticks for min, middle and max | |
| ax.yaxis.tick_right() # Show vertical ticks on the right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment