I am working with relatively large datasets (approximately 10x20.000.000 data point), for which Datashader is a useful visualisation tool. To give more information in these visualisations, I would like to add lines showing averages/standarddeviations on top of this datashade figure. Does anyone know how this would be possible?
My current code:
from bokeh.plotting import figure
from bokeh.io import show
x = 'xcol'
y= 'ycol'
data = dataframe
fig = figure(x_axis_label=x, y_axis_label=y)
points = hv.Points(data[[x, y]], label=('Title'))
hd.datashade(points, cmap='crest')
What I would like to do is for example add the following line to the figure generated with the code above:
fig.line([1,10,20], [0, 1000,2000], line_width=4)
Thanks in advance.
I am currently trying to plot a simple search trend using pytrends and pyplot. This code does display a graph and the correct line; however, it also presents a second line and I am unsure where it comes from. The picture can be seen here with the correct line in blue and the additional line in orange at the bottom. My code is as follows:
from pytrends.request import TrendReq
from matplotlib import pyplot as plt
pytrends = TrendReq(hl='en')
trend = pytrends.build_payload(['tesla'])
interest = pytrends.interest_over_time()
plt.plot(interest)
plt.grid()
plt.title('Trend')
plt.ylabel('Value')
plt.xlabel('Date')
plt.show()
The graph displays this extra line because of the isPartial column, which displays a boolean value depending on whether or not the data for a given month is complete. Adding the line del interest['isPartial'] will simply resolve the issue and present this graph without the line representing the isPartial values. Altogether, the code will look like the following:
from matplotlib import pyplot as plt
pytrends = TrendReq(hl='en')
trend = pytrends.build_payload(['tesla'])
interest = pytrends.interest_over_time()
del interest['isPartial']
plt.plot(interest)
plt.grid()
plt.title('Trend')
plt.ylabel('Value')
plt.xlabel('Date')
plt.show()
I am looking for a way to combine a bar and a line plot, without the bar plot shifting when the line plot is added.
The following code is used to generate the barplot
import matplotlib.pyplot as plt
import pandas as pd
data = pd.DataFrame([[4,30,0,3,2,2,], [5,24,0,3,1,1,], [6,34,0,4,2,1], [7,18,0,2,1,1], [8,34,0,3,3,2]], columns=['t', 'Cost', 0,1,2,3])
data[[1,2,3]].plot(kind='bar')
Thus, the data looks as follows
and the following plot is generated:
Next, I add the cost information using
data['Cost'].plot(style='o--', c='black', secondary_y=True)
Running it all together returns the following graph:
The issue is that the outer bars are no longer visible. I tried changing the range on the x-axis with xlim, but that did not help, it only made it worse. There is probably an easy fix for it, which I have not been able to find anywhere online.
I don't have the issue, running your code:
That said, an easy fix is to run ax.set_xlim(-0.5, 4.5)
I am plotting data from a .txt file using Matplotlib and although the plot looks as expected there is an odd horizontal line through the plot. This occurs across three different .txt data files I've tried. I plotted the data in Mathematica to ensure that it is not an artifact of the data. I am trying to remove the line from my data.
I've tried the accessing some of the Matplotlib methods like lines.remove() with no luck. Below is the code I'm executing and the resulting plot.
import numpy as np
import matplotlib.pyplot as plt
neon = np.loadtxt("data/neon.txt")
neon_plot = plt.plot(neon)
plt.grid()
This is an example of the horizontal line going through my plots
I am trying to generate the log-log plot of a vector, and save the generated plot to file.
This is what I have tried so far:
import matplotlib.pyplot as plt
...
plt.loglog(deg_distribution,'b-',marker='o')
plt.savefig('LogLog.png')
I am using Jupyter Notebook, in which I get the generated graph as output after statement 2 in the above code, but the saved file is blank.
Notice that pyplot has the concept of the current figure and the current axes. All plotting commands apply to the current axes. So, make sure you plot in the right axes. Here is a WME.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.loglog(range(100), 'b-',marker='o')
plt.savefig('test.png') # apply to the axes `ax`