Python Forum
Forcing matplotlib to NOT use scientific notation when graphing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forcing matplotlib to NOT use scientific notation when graphing
#1
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?
Reply
#2
I would convert time to a more suitable unit
Reply
#3
(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.
Reply
#4
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.
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ''.join and start:stop:step notation for lists ringgeest11 2 2,445 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  issue with converting a scientific notation to standard notation thomaswfirth 4 1,381 Jun-06-2023, 06:06 PM
Last Post: rajeshgk
  notation MCL169 8 1,500 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,074 Dec-06-2022, 11:09 AM
Last Post: mg24
  graphing inequalities Dasiey12 0 3,479 Mar-30-2021, 01:47 AM
Last Post: Dasiey12
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,793 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,255 Mar-11-2021, 10:52 AM
Last Post: buran
  How to understand the byte notation in python3 blackknite 3 2,932 Feb-23-2021, 04:45 PM
Last Post: bowlofred
  I need advise with developing a brute forcing script fatjuicypython 11 5,086 Aug-21-2020, 09:20 PM
Last Post: Marbelous
  Simple question concerning python dot notation. miner_tom 1 1,918 Mar-24-2020, 05:20 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020