0

I have a set of linear data and I need to plot it in python. Because there is so much data I need to plot it on a logarithmic scale but when I do using matplotlib.pyplot.xscale('log') and the same for yscale I get a curved graph not a straight line which I should get.

I'm not exactly sure what else to try other than xscale and yscale.

import matplotlib.pyplot as mpl
import sys
import numpy as np

time, rate = [], []

x = sys.argv[1]

for line in open(x, 'r'):
    column = [float(s) for s in line.split()]
    time.append(column[0])
    rate.append(column[1])

mpl.xscale('log')
mpl.yscale('log')
mpl.plot(time, rate)
mpl.show()

The expected result should be a linear decreasing graph on a logarithmic scale. Is there a way to have a logarithmic scale on a graph without changing the values to logarithmic? Or is that what mpl.yscale('log') does?

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
awsc
  • 27
  • 1
  • Read [this](https://stackoverflow.com/questions/48858854/how-to-apply-logarithmic-axis-labels-without-log-scaling-image-matplotlib-imsho) too – Sheldore Jan 19 '19 at 22:45

1 Answers1

0

Have a look at the following website. This tells you how you can change your code to force it into creating the straight line for your data. However, it won't be as accurate as using a curved line for reading off predictions.

Linear Fit in matplotlib

James
  • 53
  • 1
  • 7