Python Forum
Forcing matplotlib to NOT use scientific notation when graphing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Forcing matplotlib to NOT use scientific notation when graphing (/thread-41829.html)



Forcing matplotlib to NOT use scientific notation when graphing - sawtooth500 - Mar-23-2024

I have a dataset that I'm importing from a CSV into a dataframe in python. I need to make a simple line graph out of it.

Here is my code:

# Create the line graph
plt.plot(x_values, y_values, marker='o', linestyle='-')
# Customize the x-axis tick formatter
#plt.gca().xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=False))
plt.ticklabel_format(useOffset=False)
#plt.gca().xaxis.set_major_formatter(ticker.ScalarFormatter(useOffset=False))

# Add labels and title
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Data')

# Display the graph
plt.grid(True)  # Add grid lines
plt.show()
So my Y axis data ranges in value from 190-197 and has a precision of two decimal places. Simple enough. My X axis data however is time measured in nanoseconds - and my data set spans an hour of time starting at 34200001686628 and ending at 37798014509685 - I have about 27300 data points in my data set. I am graphic this because I want to be able to zoom in and look at the microscale data when graphed. The problem is no matter what I seem to try, matplotlib uses scientific notation on the X axis. In order to make sense of my data, I need to see the full timestamps - with no scientific notation. I have tried:

plt.gca().xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=False))
plt.ticklabel_format(useOffset=False)
plt.gca().xaxis.set_major_formatter(ticker.ScalarFormatter(useOffset=False))

And still it's showing as scientific notation. Any advice on how to force it to use the full number?


RE: Forcing matplotlib to NOT use scientific notation when graphing - deanhystad - Mar-24-2024

I would convert time to a more suitable unit


RE: Forcing matplotlib to NOT use scientific notation when graphing - sawtooth500 - Mar-24-2024

(Mar-24-2024, 12:48 AM)deanhystad Wrote: I would convert time to a more suitable unit

I have time converted to a more human readable format such as 09:31:10.305124096 in my excel file for my personal reference... however I still need to retain the nanosecond precision for my application. I need the x axis on my graph to be linear in scale.


RE: Forcing matplotlib to NOT use scientific notation when graphing - deanhystad - Mar-24-2024

You don't need "nanosecond" precision for a plot. If you can't stand that 1e6 in on the axis label, convert x to seconds

I find it difficult to believe that 27,300 points can be plotted using marker='o'. All I see is a fizzy line.


RE: Forcing matplotlib to NOT use scientific notation when graphing - sawtooth500 - Mar-25-2024

Well, you are completely correct, all you see is a fizzy line.

What I was hoping though was to use the python image viewer to zoom in at will to see the microstructure wherever I wanted to.

Ultimately, on my X axis, since I want it to be linear scale, I figured having nanosecond time such as 35163106216951 would be the easiest. Then, ultimately I was hoping to be able to label each nanosecond time on the graph with a human readable equivalent, for example for the above time it is 09:46:03.106216960. When I zoom in now, no matter how close I zoom I keep getting these rounded 1e6 values, so when I zoom in on the microscale it's next to impossible to correlate where it is relative to the timeframe. That's why I was just hoping to be able to get the full nanosecond values on zoom in, along with a corresponding human time label for each nanosecond value.