I am a beginner in python trying to plot candlestick chart of stocks but am unable to do so. Matplotlib offers all charts except candlesticks. Any suggestions as to how i can achieve the results?
enter image description here
Import this library with pandas and use as the example below. Then you will be able to perform some candlestick plots.
import plotly.graph_objects as go
import pandas as pd
from datetime import datetime
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
open=df['AAPL.Open'],
high=df['AAPL.High'],
low=df['AAPL.Low'],
close=df['AAPL.Close'])])
fig.show()
Related
I have this csv data file, I'm trying to create a pie chart using this data
I am a beginner in Python and don't understand how to create a pie chart using CSV
my code:
`
import pandas as pd
from matplotlib.pyplot import pie, axis, show
df = pd.read_csv ('hasil.csv')
sums = df.groupby(df["Analysis"]) ["Polarity"].sum()
axis('equal')
pie(sums, labels=sums.index)
show()
`
working solution code would be more helpful!
Probably something really simple.
I use an example to plot a Candlestick chart using plotly, but the plot never show up!?
This is the code from https://plot.ly/python/candlestick-charts/
import plotly.graph_objects as go
import pandas as pd
from datetime import datetime
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
open=df['AAPL.Open'],
high=df['AAPL.High'],
low=df['AAPL.Low'],
close=df['AAPL.Close'])])
fig.show()
I'm using last updated python and spyder4 on anaconda. I usually use matplotlib without problem.
It is an issue already considered in the plotly community:
import plotly.graph_objects as go
from plotly.offline import iplot
import pandas as pd
from datetime import datetime
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
open=df['AAPL.Open'],
high=df['AAPL.High'],
low=df['AAPL.Low'],
close=df['AAPL.Close'])])
iplot(fig)
(My first ever StackOverflow question)
I'm trying to plot bitcoin's market-cap against the date using pandas and matplotlib in Python.
Here is my code:
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#read in CSV file using Pandas built in method
df = pd.read_csv("btc.csv", index_col=0, parse_dates=True)
Here are some details about the data frame:
dataframe details
matplotlib code:
#Plot marketcap(usd)
plt.plot(df.index, df["marketcap(USD)"])
plt.show()
Result:
Incorrect result
The plot seems to be more like scribbles that seem to move backwards. How could I fix this?
You can plot your Pandas Series "marketcap(USD)" directly using:
df["marketcap(USD)"].plot()
See the Pandas documentation on Basic Plotting
I want the x axis tick marks to be the different states ie. IDLE, Data=Addr, Hammer, etc that are in column A of the csv file.
import pandas as pd
import matplotlib.pyplot as plt
df1 = pd.read_csv("Output.csv", index_col = 0)
df1.plot(x = df1.index.values)
I have also tried
df1.plot(xticks = df1.index.values)
without any success.
CSV File
Plot
Thanks in advance!
You may want to try Seaborn because it looks like it is not a plotting issue but rather peripheral styling issue (all blacked out) in your environment.
Once you installed Seaborn, insert a piece of code below to yours.
import seaborn as sns
sns.set_style("whitegrid")
As a side note, if you wish to align the number of ticks in x axis to that of labels you have, replace your plotting part with the following:
df1.plot()
plt.xticks(range(df1.shape[0]), df1.index)
Hope this helps.
I am currently facing an import issue with pandas.tools.plotting. I try to import the scatter matrix via
from pandas.tools.plotting import scatter_matrix
But I get the following error message from visual studio code:
[pylint] E0611:No name 'scatter_matrix' in module
'pandas.tools.plotting'
I also tried
from pandas.tools import scatter_matrix
but it didn't work either. Why can't I import the scatter matrix?
I am using
python 3.6.4
pandas 0.22.0
You need to use this line of code to import pandas scatter_matrix. As seen in the docs of pandas visualization.
from pandas.plotting import scatter_matrix
e.g.
scatter = pd.plotting.scatter_matrix(X, c = y, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap = cmap)