How to rotate the matplotlib figure?

python matplotlib

20 观看

1回复

115 作者的声誉

I am new in python and I am using code from here to plot the mean and std:

df = pd.read_csv('file.csv')
x = df['index']
y = df['mean']
e = df['std']

plt.figure(figsize=(18, 6))
plt.errorbar(x, y, e, linestyle='None', marker='^')
plt.xticks(x, rotation=45)
plt.xlabel('test', fontsize=16)
plt.ylabel('size', fontsize=16)
plt.tight_layout()

I want to rotate the plot 90 degree and I tried to find the way to do from matplotlib documentation but I couldn't. Is there any way that I can rotate this plot.

作者: Bilgin 的来源 发布者: 2019 年 8 月 13 日

回应 1


0

752 作者的声誉

I am not quite sure if I got your question right, but I am going to give it a shot. You can try out the following code

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import pyplot, transforms

x = np.array([1, 2, 3, 4, 5])
y = np.power(x, 2) # Effectively y = x**2
e = np.array([1.5, 2.6, 3.7, 4.6, 5.5])

base = pyplot.gca().transData
rot = transforms.Affine2D().rotate_deg(-90)


plt.errorbar(x, y, e, linestyle='None', marker='^', transform = rot + base)
plt.xticks(x, rotation=45)
plt.xlabel('test', fontsize=16)
plt.ylabel('size', fontsize=16)
plt.tight_layout()
plt.show()

outputs enter image description here

作者: Axois 发布者: 2019 年 8 月 13 日
32x32