I intended to plot a trend of daily BTC prices, which is recorded as a csv file, consisting of a sequence of 3892 numbers.
Being a csv file, I could use microsoft excel to plot the trend.
It looks like this;
Meanwhile, I attempted to do the same thing using pandas and matplotlib in a jupyter notebook, which doesn't look good;
What's wrong with my implementation?
One more thing is the implementing time ; it takes a quite a while, like one or two minute.
This is not the case when I put a code and implement like this ;
plt.plot(list(range(1000)),list(range(1000)))
Here is the full code for my attempt.
import pandas as pd
from matplotlib import pyplot as plt
df=pd.read_csv('BTC_inv_daily.csv')
Close=df['Close'].tolist()
N=len(Close)
plt.plot(list(range(N)),Close)
plt.show()
Related
I'm trying to plot a radioisotope's power output by time. For this, I've found the following equation:
without the exponential at the end it works but I need the difference by time so I need to use it but I can't make that part work.
This is my code:
import matplotlib.pyplot as plt
import numpy as np
import math
ln2=0.693
avon=6.02214076*(10**23)
mevj=1.6*(10**(-13))
t = np.array(range(50))
co60 = (((ln2)/(5.27*365*24*3600))*((avon)*mevj*2.505/60))/(2.718**((ln2)/(5.27*365*24*3600)*(t))))
plt.plot(t, co60, label='co60')
This gives a wrong output. I can't get an exponential plot. I used 2.718 for e since when I use math.exp it gives errors. The correct output must be like the black line.
I think I'm having troubles with using the mathematical dynamics of python and couldn't interpret the equation correctly. Could you help?
Thanks.
I am using python 3.8 on Windows 10; trying to make a plot with about 700M points in it, sound wave analysis. Here: Interactive large plot with ~20 million sample points and gigabytes of data
Vaex was highly recommended. I am trying to use examples from the Vaex tutorial but the graph does not appear. I could not find a good example on Internet.
import vaex
import numpy as np
df = vaex.example()
df.plot1d(df.x, limits='99.7%');
The Vaex documents don't mention that pyplot.show() should be used to display. Plot1d plots a histogram. How to plot just connected points?
I am pretty sure that the vaex documentation explains that the (now deprecated) method .plot1d(...) is a wrapper around matplotlib plotting routines.
If you would like to create custom plots using the binned data, you can take this approach (I also found it in their docs)
import vaex
import numpy as np
import pylab as plt
# Load example data
df = vaex.example()
# Do the binning yourself
counts = df.count(binby=df.x, shape=64, limits='99.7%')
# Take care of the x-axis
limits = df.limits_percentage(df.x, percentage=99.7)
xvals = np.linspace(limits[0], limits[1], num=64)
# Create your custom plot via matplotlib, plotly or your favorite tool
p.plot(xvals, counts, marker='o', ms=5);
I am trying to move from matplotlib to bokeh. However, I am finding some annoying features. Last I encountered was that it took several minutes to make an histogram of about 1.5M entries - it would have taken a fraction of a second with Matplotlib. Is that normal? And if so, what's the reason?
from bokeh.charts import Histogram, output_file, show
import pandas as pd
output_notebook()
jd1 = pd.read_csv("somefile.csv")
p = Histogram(jd1['QTY'], bins=50)
show(p)
I'm not sure offhand what might be going on with Histogram in your case. Without the data file it's impossible to try and reproduce or debug. But in any case bokeh.charts does not really have a maintainer at the moment, so I would actually just recommend using bokeh.plotting to create your historgam. The bokeh.plotting API is stable (for several years now) and extensively documented. It's a few more lines of code but not many:
import numpy as np
from bokeh.plotting import figure, show, output_notebook
output_notebook()
# synthesize example data
measured = np.random.normal(0, 0.5, 1000)
hist, edges = np.histogram(measured, density=True, bins=50)
p = figure(title="Normal Distribution (μ=0, σ=0.5)")
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color=None)
show(p)
As you can see that takes (on my laptop) ~half a second for a 10 million point histogram, including generating synthetic data and binning it.
I am trying to plot a pandas data frame that looks like below using Seaborn:
Date | Size | Volatility |Liquidity |Value |Growth |Medium-Term Momentum Leverage |Exchange Rate Sensitivity
2015-12-01 |0.544913 |0.148974 |0.054775 |0.022000 |0.017445 |0.016755 -0.036878 |0.022004
2015-12-02 |-0.205794 |-0.269582 |-0.000488 |-0.061183 |0.015816 |0.067442 -0.034935 |0.051987
2015-12-03 |-0.487403 |-0.284386 |0.003767 |0.031578 |-0.022917 |0.045993 0.019988 |-0.034294
What I am trying to achieve is something like this:
How do I use Seaborn data library for this?
I have already checked the questions on stackoverflow regarding this, one suggestion was to use matplotlib, but I am looking to purely use seaborn to accomplish the task.
As you can see on the Seaborn installation page, matplotlib is a mandatory dependency of seaborn.
In fact, seaborn (at the most basic level) merely changes the default style of matplotlib plots, so won't work without it. You might achieve what you're looking to do by simply doing:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df.Size.plot
Which uses pandas plotting functionality with seaborn default style.
I am using ipython notebook with pylab --inline
import matplotlib.pyplot as plt
import pandas as pd
......
plt.figsize(14,8)
ax1=plt.subplot(311)
#data is a pandas data frame with timeseries stock data
# this plots the data
data.plot(ax=ax1)
This shows a plot of the stock data but its all displayed at once.
I would like to display just subrange of dates and have a scrollbar to control what range
How do I do it such that it works with the inline display of plots.
You can't. Inline display is a static PNG.
If you want something like that you will have to use a Javascript plotting library for now.
None that I know of will work out of the box with panda.
You can't manipulate plots in inline-mode after they have been drawn. However, you can scale,zoom and resize plots in the interactive mode. Just start your notebook without the inline-option and all plots will be generated in an extra window with the functionality you asked for:
ipython notebook --pylab