I'm building a python application to keep track of the BTC values over time through a graph that updates in realtime; in the x axis there is time and in the y axis the value of the corresponding BTC. my problem is that at the beginning the BTC values in the y axis are correct as in the first figure, but after some data received, the graph decides to "zoom" and express all the data in a different notation, as in the second figure (open imgur link).
https://imgur.com/a/spogs9G
I tried these two lines of code but without success:
plt.autoscale(enable=False, axis='y')
ax.get_yaxis().get_major_formatter().set_scientific(False)
If it can help, i am using:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
If you would like to see all or part of the code, please ask.
Thank you in advance.
Fix the y-axis by using (as an example):
ax.set_ylim(0,1000)
and define the lower and upper bound accordign to your problem.
ax.set_ylim(lower_bound,upper_bound)
I am using bqplot to create a live line graph on jupyter-notebook + VOILA
from bqplot import pyplot as plt2
import datetime
x_values = [] #array of datetimes
y_values = [] #array of 10+ digit numbers
plt2.show()
def functionThatIsCalledRepeatedly(x_val, y_val):
x_values.append(x_val)
y_values.append(y_val)
plt2.plot(x_values, y_values)
Part of the Resulting Plot
My question is, how do I remove the scientific notation from the y-axis. It's a simple task but I have tried a lot of things.
I tried using axes.tick_format property of the graph but I think that only works if you have axes objects which I cannot have because they require the mandatory Scale property which I cannot use because the graph is live and the x and y scales need to be generated/recalibrated while it runs.
I tried changing y_values.append(y_val) to y_values.append("{:.2f}".format(y_val)) but that converts to a string and bqplot doesn't process it as a number so it ends up with negative numbers on top of the 0 sometimes.
I tried converting to a numpy array and then doing np.set_printoptions(suppress=True) which (obviously) didn't work.
Basically tried a lot of things and I think it comes down to some bqplot property that may or may not exist. Have been stuck for a while. Thank you!
You can provide axes options with the tick format you want to the plot method:
plt2.plot(x_values, y_values, axes_options={
y=dict(tick_format='0.2f')
})
You can see examples of this axes_options (using a scatter plot, but that should work the same) in this notebook: https://github.com/bqplot/bqplot/blob/master/examples/Marks/Pyplot/Scatter.ipynb
I have a large data set (growing number of x axis), the one shown at the bottom is enough to reproduce my case. I'm trying to plot this using Pandas and matplotlib. [I'm very new with python, so apologies in advance for any mistakes.]
import os
import sys
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test.csv', delimiter=',', index_col='Header')
df.plot(marker='s', figsize=(18,9))
plt.title("test")
plt.ylabel('y axis')
plt.xlabel('x axis')
plt.show()
sys.exit()
When I use the code above, it plots the graph, but I've got few issues.
Y axis data points looks they have been scaled (which I did not ask)
Missing few x axis data points, I understated it may not possible display all X axis values on the axis, which is fine. I was wondering would it be possible to display them on the actual data point when I move the mouse over them.
The latter is really crucial feature I'm after. My script is intended to track some data and when there is a visible bump in the plot, I need to be able to know which X values actually cause the bump. If anyone has suggestion for achieving the similar effect, they are much appreciated.
Header,header1,header2,header3,header4,header5,header6
x1,2115211,2223666,13332666,8448144,655564,366361
x2,2115213,2223666,13332666,8448144,655564,366361
x3,2115213,2223666,13332666,8448144,655564,366361
x4,2115213,2223666,13332666,8448144,655564,366361
x5,2115262,2229973,13330187,8448756,655523,366379
x6,2115262,2229973,13330187,8448756,655523,366379
x7,2115262,2229973,13330187,8448756,655523,366379
x8,2115277,2228613,13335478,8448221,655556,366362
x9,2115277,2228613,13335478,8448221,655556,366362
x10,2115211,2223666,13332666,8448144,655564,366361
x11,2115213,2223666,13332666,8448144,655564,366361
x12,2115213,2223666,13332666,8448144,655564,366361
x13,2115213,2223666,13332666,8448144,655564,366361
x14,2115213,2223666,13332666,8448144,655564,366361
x15,2115262,2229973,13330187,8448756,655523,366379
x16,2115262,2229973,13330187,8448756,655523,366379
x17,2115262,2229973,13330187,8448756,655523,366379
x18,2115277,2228613,13335478,8448221,655556,366362
x19,2115277,2228613,13335478,8448221,655556,366362
Any help is much appreciated.
I am using Python 2.7 and need to draw a time series using matplotlib library. My y axis data is numeric and everything is ok with it.
The problem is my x axis data which is not numeric, and matplotlib does not cooperate in this case. It does not draw me a time series even though it is not supposed to affect the correctness of the plot, because the x axis data is arranged by a given order anyway and it's order does not affect anything logically.
For example let's say the x data is ["i","like","python"] and the y axis data is [1,2,3].
I did not add my code because I've found that the code is ok, it works if I change the data to all numeric data.
Please explain me how can I use matplotlib to draw the time series, without making me to convert the x values to numeric stuff.
I've based my matplotlib code on following answers: How to plot Time Series using matplotlib Python, Time Series Plot Python.
Matplotlib requires someway of positioning those labels. See the following example:
import matplotlib.pyplot as plt
x = ["i","like","python"]
y = [1,2,3]
plt.plot(y,y) # y,y because both are numeric (you could create an xt = [1,2,3]
plt.xticks(y,x) # same here, the second argument are the labels.
plt.show()
, that results in this:
Notice how I've put the labels there but had to somehow say where they are supposed to be.
I also think you should put a part of your code so that it's easier for other people to suggest upon.
Consider the following code
import matplotlib.pyplot as plt
import numpy as np
time=np.arange(-100,100,01)
val =np.sin(time/10.)
time=-1.0*time
plt.figure()
plt.plot(time,val)
plt.xlim([70,-70])
plt.savefig('test.pdf')
when I open the pdf in inkscape, I can select (with F2) the entire data, it's just invisible outside of the specified xlim interval:
The problem seems to be the line
time=-1.0*time
If I omit this line, everything works perfectly.. no idea why this is. I often need such transformations because I deal with paleo-climate data which are sometimes given in year B.C. and year A.D., respectively.
The problem I see with this behavior is that someone could in principle get the data outside the range which I want to show.
Has someone a clue how to solve this problem (except for an slice of the arrays before plotting)?
I use matplotlib 1.1.1rc2
You can mask your array when plotting according to the limits you choose. Yes, this also requires changes to the code, but maybe not as extensive as you might fear. Here's an updated version of your example:
import matplotlib.pyplot as plt
import numpy as np
time=np.arange(-100,100,01)
val =np.sin(time/10.)
time=-1.0*time
plt.figure()
# store the x-limites in variables for easy multi-use
XMIN = -70.0
XMAX = 70.0
plt.plot(np.ma.masked_outside(time,XMIN,XMAX),val)
plt.xlim([XMIN,XMAX])
plt.savefig('test.pdf')
The key change is using np.ma.masked_outside for your x-axis value (note: the order of XMIN and XMAX in the mask-command is not important).
That way, you don't have to change the array time if you wanted to use other parts of it later on.
When I checked with inkscape, no data outside of the plot was highlighted.