1

I'm trying to create a correlation matrix plot with matplotlib in python. However I'm not able to make the x and y ticks to be in the middle of each square and also I need the xticks to be vertical. I need them vertical because I will have about 15 variables to plot, so having the ticks in horizontal way won't fit.

Here is my attempt:

import numpy as np
import matplotlib.pyplot as plt

X = np.random.randn(10,3)
X = X.T
R = np.corrcoef(X)
plt.figure()
plt.xticks([0,1,2], ["first", "second", "third"], rotation='vertical')
plt.yticks([0,1,2], ["first", "second", "third"])
plt.pcolor(R)

Result:

enter image description here

Edit: I just figured out that using rotation='vertical' solves the x-ticks demand for me.

1 Answer 1

1

To centralise the ticks you need to add 0.5 to each value:

plt.yticks([0.5,1.5,2.5], ["first", "second", "third"])
plt.xticks([0.5,1.5,2.5], ["first", "second", "third"], rotation='vertical')

Also, you might want to add the following so that the overall figure size is adjusted to take account of the rotated x labels:

plt.tight_layout()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.