1

I am trying to rotate plot inside matplotlib figure by 90 degree. I found out this post but it uses pyplot and I am using simple plot so that does not work, Also he doesn't explain the code for rotating pyplot but mentions transform property can also be used to rotate simple plot graph. I tried searching online for transformation tutorial but could not understand the concept.

Here is me code snippet

from matplotlib.figure import Figure
import numpy

# random data
data = numpy.random.randn(100)

# making figure on which plot will be draw
fig = Figure(figsize=(11, 8),dpi=100)
# adding plot to figure
plot1 = fig.add_subplot(111)
# plotting values
plot1.plot(data)

# saving figure for later use
fig.savefig("graph.jpeg")

It produces following result;

current output

But I want this kind of output;

required output

abdulsamad
  • 158
  • 1
  • 10

1 Answers1

4

To rotate graph you can use this trick by changing axis (x, y) -> (y, x) and rotate current x-axis:

x = numpy.arange(100)
data = numpy.random.randn(100)
plot1.plot(-data, x)
Davinder Singh
  • 2,060
  • 2
  • 7
  • 22
  • 1
    This trick worked for me ... cheers! only thing I have to change was the - operand with data as I am not working with numpy array but python list So I used list comprehension to achieve it `data = [ -x for x in data]` – abdulsamad Mar 18 '21 at 05:24