![]() ![]() grid ( axis = 'y', color = '0.9' ) #add a light grid ax. arrow ( arrow_starts, #x start point i, #y start point arrow_lengths, #change in x 0, #change in y head_width = 0.6, #arrow head width head_length = 0.2, #arrow head length width = 0.2, #arrow stem width fc = 'black', #arrow fill color ec = 'black' ) #arrow edge color #format plot ax. values - arrow_starts #add arrows to plot for i, subject in enumerate ( data ): ax. stripplot ( data = data, x = 'before', y = 'subject', orient = 'h', order = data, size = 10, color = 'black' ) #define arrows arrow_starts = data. figure ( figsize = ( 5, 10 )) #add start points ax = sns. reset_index ( drop = True ) #initialize a plot ax = plt. sort_values ( by = 'change', ascending = False ) \ #sort individuals by amount of change, from largest to smallest data = data. Here's what the arrow plots looked like in the poster: after stimulation, but I thought replacing the points with an arrow pointed in the direction of the change would make for a simpler, more intuitive plot. Normally I would use a strip plot with different colored points for before vs. We only observed this pattern in one condition and I wanted to visualize how participants' decision criteria changed before vs. At the group level, our lab found that stimulating the right inferior frontal gyrus with repetitive Transcranial Magnetic Stimulation made participants more cautious to identify previously studied faces during a recognition memory experiment. I first made the plot when I was trying to illustrate the variability in individuals' responses to neurostimulation. Regardless of whether it's an actual type of plot or not, I've found them useful in visualizing changes in some variable across individuals and this post describes how to make them in Python. Plotfigure(lambda: plt.scatter(range(0,len(y)), y, marker=".After a quick Google search, I realize that there may not be such a thing as an arrow plot and I may have made up the term. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=27) X, y = make_classification(n_samples=50, n_classes=2, n_features=5, random_state=27) Supports matlplotlib colorsĪ use case is defined below from sklearn.datasets import make_classificationįrom sklearn.model_selection import train_test_split Supports matlplotlib colorsįace_col: The face color of the plot. ![]() Plot_fn (func): The plot functions with necessary arguments as a lamdda function.īackground_col: The background color of the plot. ![]() def plotfigure(plot_fn, fig, background_col = 'xkcd:black', face_col = (0.06,0.06,0.06)):Ĭustomize different background and face-colors of the plot. Here is a utility function that takes a plotting function with necessary args and plots the figure with required background-color styles. import matplotlib.pyplot as pltĪx2=fig.add_subplot(111, label="2", frame_on=False)Īx3=fig.add_subplot(111, label="3", frame_on=False)Īx.plot(x_values1, y_values1, color="C0")Īx2.scatter(x_values2, y_values2, color="C1")Īx2.t_label_position('bottom') # set the position of the second x-axis to bottomĪx2.t_position(('outward', 36))Īx3.plot(x_values3, y_values3, color="C2")Īx3.t_position(('outward', 72))Īx3.t_position(('outward', 36)) Motivated by previous contributors, this is an example of three axes. G = sns.relplot(kind='line', data=df, x='date', y='a', color='g', aspect=2)Īx.spines].set_visible(True) Seaborn figure-level plot # plot the dataframe and assign the returned axes Seaborn axes-level plot import seaborn as sns # plot the dataframe and assign the returned axesĪx = df.plot(x='date', color='green', ylabel='values', xlabel='date', figsize=(8, 6))Īx.tick_params(colors='red', which='both') # 'both' refers to minor and major axes This snippet yields two figures, the first one with modified colors for the axis, ticks and ticklabels, and the second one with the default rc parameters. The context manager allows you to temporarily change the rc parameters only for the immediately following indented code, but does not affect the global rc parameters. If you have several figures or subplots that you want to modify, it can be helpful to use the matplotlib context manager to change the color, instead of changing each one individually. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |