![]() |
strange behaviour- plotting - 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: strange behaviour- plotting (/thread-31682.html) |
strange behaviour- plotting - nathan_Blanc_Haifa - Dec-27-2020 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() |