0

I want to plot my graph with a scientific number in y-axis. I have used ticklabel format from matplotlib. But I am not getting my desire output in y-axis label. I have attached my script with output image (image_1) and image_2 is my desire one.

Code:

import numpy as np
import matplotlib.pyplot as plt

x1, y1 = [], []
label_added =False
with open("50kev_vacancy.txt") as f:
    for line in f:
        cols = line.split()

        x1.append(float(cols[0]))
        y1.append(float(cols[3]))
        if not label_added:
            plt.plot(x1,y1,'b-', label="50kev")
            label_added = True
        else:
            plt.plot(x1,y1,'b-')
plt.title('Different PKA energy')
plt.xlabel('time_ps')
plt.ylabel('Number of vacancy')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
legend = plt.legend(loc='upper center', shadow=True, fontsize='x-large')
plt.tight_layout()
plt.savefig("Different_PKA_energy_vacancy_vs_time.jpeg", dpi=50)

Output: enter image description here

desired output:

enter image description here

Alex
  • 47
  • 6
  • 1
    Possible duplicate of [Can I show decimal places and scientific notation on the axis of a matplotlib plot using Python 2.7?](https://stackoverflow.com/questions/25750170/can-i-show-decimal-places-and-scientific-notation-on-the-axis-of-a-matplotlib-pl) – rpanai Apr 18 '19 at 01:47
  • You can check [doc](https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.ticklabel_format.html) and I guess it will be easier read your `txt` fike with `pandas` or `numpy`. In the last case you can use [this](https://stackoverflow.com/a/3519314/4819376). – rpanai Apr 18 '19 at 01:50
  • Dear Sir, thank you for your quick response. I have checked your two replies and this is not helpful for me. If you see my coding, I have used also sci formate from matplotlib. But I need 10^1 , 10^2, 10^3, 10^4 etc. not like 1*10^1 , 1*10^2.... – Alex Apr 18 '19 at 03:31
  • 1
    @Alex Maybe you mean `plt.set_yscale('log')`? – Tom de Geus Apr 18 '19 at 06:26
  • 1
    @TomdeGeus you meant to write: `plt.xscale('log')` or `plt.yscale('log')` :-) – Asmus Apr 18 '19 at 08:09
  • 1
    Set both x and y axis to be logarithmic – Sheldore Apr 18 '19 at 08:09
  • @Asmus Obviously :-) – Tom de Geus Apr 18 '19 at 11:17
  • Dear Sir, thank you very much. I had no idea it is about log scale. but it is working now. Thank you again – Alex Apr 22 '19 at 00:12

0 Answers0