Plot correlation matrix using pandas

You can use pyplot.matshow() from matplotlib: import matplotlib.pyplot as plt plt.matshow(dataframe.corr()) plt.show() Edit: In the comments was a request for how to change the axis tick labels. Here’s a deluxe version that is drawn on a bigger figure size, has axis labels to match the dataframe, and a colorbar legend to interpret the color scale. … Read more

How to plot a histogram using Matplotlib in Python with a list of data?

If you want a histogram, you don’t need to attach any ‘names’ to x-values because: on x-axis you will have data bins on y-axis counts (by default) or frequencies (density=True) import matplotlib.pyplot as plt import numpy as np %matplotlib inline np.random.seed(42) x = np.random.normal(size=1000) plt.hist(x, density=True, bins=30) # density=False would make counts plt.ylabel(‘Probability’) plt.xlabel(‘Data’); Note, … Read more

Moving x-axis to the top of a plot in matplotlib

Use ax.xaxis.tick_top() to place the tick marks at the top of the image. The command ax.set_xlabel(‘X LABEL’) ax.xaxis.set_label_position(‘top’) affects the label, not the tick marks. import matplotlib.pyplot as plt import numpy as np column_labels = list(‘ABCD’) row_labels = list(‘WXYZ’) data = np.random.rand(4, 4) fig, ax = plt.subplots() heatmap = ax.pcolor(data, cmap=plt.cm.Blues) # put the major … Read more

seaborn is not plotting within defined subplots

From the documentation for seaborn.distplot, which has been DEPRECATED in seaborn 0.11. .distplot is replaced with the following: displot(), a figure-level function with a similar flexibility over the kind of plot to draw. This is a FacetGrid, and does not have the ax parameter. histplot(), an axes-level function for plotting histograms, including with kernel density … Read more