Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strange behaviour- plotting
#1
I am trying to plot to vectors against one another. when I don't touch the ticks, I get ticks with 16 digits that overlap. when I try to change the tick format the values of the ticks themselves change, and display the index instead of the vector value. I wanted to upload the files and screenshots but couldn't do it. my code is:
import csv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

plt.rcParams.update(plt.rcParamsDefault)

#import data
with open('hw3_ex1.csv', newline='') as csvfile:
    data = list(csv.reader(csvfile))
data=np.array(data)
N=data.shape[0]
data=data[1:N-1,:]

m=data.shape[0]  #number of points
dp=data[:,0]     #pressure difference
Q=data[:,1]      # flow rate
plt.plot(dp.tolist(),Q.tolist())
#plt.scatter(dp,Q)
axes= plt.axes()
axes.xaxis.set_major_locator(plt.MaxNLocator(5))
axes.yaxis.set_major_locator(plt.MaxNLocator(5))
#these lines should be uncommented to see the second screenshot
#axes.yaxis.set_major_formatter(ticker.StrMethodFormatter("{x:.1f}"))
#axes.xaxis.set_major_formatter(ticker.StrMethodFormatter("{x:.1f}"))
#axes.set_xticks(5)
#axes.set_yticks(5)
plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 853 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  can someone explain this __del__ behaviour? rjdegraff42 1 692 Apr-12-2023, 03:25 PM
Last Post: deanhystad
  Asyncio weird behaviour vugz 2 1,190 Apr-09-2023, 01:48 AM
Last Post: vugz
  Weird behaviour using if statement in python 3.10.8 mikepy 23 3,427 Jan-18-2023, 04:51 PM
Last Post: mikepy
  Generator behaviour bla123bla 2 1,072 Jul-26-2022, 07:30 PM
Last Post: bla123bla
  Inconsistent behaviour in output - web scraping Steve 6 2,445 Sep-20-2021, 01:54 AM
Last Post: Larz60+
  Adding to the dictionary inside the for-loop - weird behaviour InputOutput007 5 2,651 Jan-21-2021, 02:21 PM
Last Post: InputOutput007
  Behaviour of 2D array SimonB 6 2,759 Jan-21-2021, 01:29 PM
Last Post: SimonB
  OOP behaviour problem JohnB 3 2,393 Aug-18-2020, 07:51 PM
Last Post: JohnB
  understanding basic loop behaviour vinci 5 2,811 Feb-11-2020, 09:53 PM
Last Post: vinci

Forum Jump:

User Panel Messages

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