Issue
I have below code from this - 2nd answer
import pandas as pd
import numpy as np
rs = np.random.RandomState(0)
df = pd.DataFrame(rs.rand(10, 10))
corr = df.corr()
corr.style.background_gradient(cmap='coolwarm')
it prints this. How can i rotate column names by 90 degrees in the below image?
Update 1
I updated code as below but it didnt help
import pandas as pd import numpy as np
rs = np.random.RandomState(0)
df = pd.DataFrame(rs.rand(10, 10))
corr = df.corr()
corr.style.set_table_styles(
[dict(selector="th",props=[('max-width', '80px')]),
dict(selector="corr.col_heading",
props=[("writing-mode", "vertical-rl"),
('transform', 'rotateZ(-90deg)'),
])])
corr.style.background_gradient(cmap='coolwarm')
Solution
Here is how to do it:
import numpy as np
import pandas as pd
rs = np.random.RandomState(0)
df = pd.DataFrame(rs.rand(10, 10))
df.corr().style.background_gradient(cmap="coolwarm").set_table_styles(
[
dict(
selector="th.col_heading",
props=[
("writing-mode", "vertical-rl"),
("transform", "rotateZ(180deg)"),
("height", "5px"),
],
),
]
)
Which outputs:
Answered By - Laurent
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.