Created
July 21, 2023 17:44
-
-
Save kururu-abdo/1fd2fb43a715e9c4ad794e26dade652b 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
| import matplotlib.pyplot as plt | |
| %matplotlib inline | |
| #box plot // to show relation between | |
| sns.boxplot(x="body-style", y="price", data=df) | |
| #reg plot -- to show relation degree | |
| sns.regplot(x="peak-rpm", y="price", data=df) | |
| #heatmap plot | |
| df_gptest = df[['drive-wheels','body-style','price']] | |
| grouped_test1 = df_gptest.groupby(['drive-wheels','body-style'],as_index=False).mean() | |
| grouped_test1 | |
| grouped_pivot = grouped_test1.pivot(index='drive-wheels',columns='body-style') | |
| grouped_pivot | |
| plt.pcolor(grouped_pivot, cmap='RdBu') | |
| plt.colorbar() | |
| plt.show() | |
| #hitmap plot with lables | |
| fig, ax = plt.subplots() | |
| im = ax.pcolor(grouped_pivot, cmap='RdBu') | |
| #label names | |
| row_labels = grouped_pivot.columns.levels[1] | |
| col_labels = grouped_pivot.index | |
| #move ticks and labels to the center | |
| ax.set_xticks(np.arange(grouped_pivot.shape[1]) + 0.5, minor=False) | |
| ax.set_yticks(np.arange(grouped_pivot.shape[0]) + 0.5, minor=False) | |
| #insert labels | |
| ax.set_xticklabels(row_labels, minor=False) | |
| ax.set_yticklabels(col_labels, minor=False) | |
| #rotate label if too long | |
| plt.xticks(rotation=90) | |
| fig.colorbar(im) | |
| plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment