I have created a local html plotly graph which I intend to run from a server, every time the script ends it opens the html, is there something I can use which will prevent this happening?
thanks
Yep! Just looking at script, find in the end line, where plotly draw a plot. It should look such this:
plotly.offline.plot(fig)
And add parameter auto_open and specify it to False:
plotly.offline.plot(fig, auto_open = False)
Hope it helps!
Related
problem
I have a problem with matplotlib. I looked at a lot of things online (including an extensive amount of stack overflow questions) and did not find an answer to my problem. To be clear: I know how to dynamically update a plot in matplotlib. Everything I find online deals with showing the plot AFTER having set the series. here the problem is different. Please see the code below.
I have simulation results being written on the fly in a file (let's say file.log). I have a current code that prints the results on the fly as well using matplotlib. the problem is that, for various reasons, sometimes a new variable is written in file.log. But the monitoring is already displayed. How can I add a lineplot to the existing plot and keep updating ?
Here I give the general structure of the code I have.
The code structure I have
shell command:
I tail the log file one line by one line and pipe the output to a python script which handles the line in a for loop (this is working fine, no problem with that).
tail -f -n 1 file.log | monitoring.py
The python. It is commented line by line. Sorry for the long code sequence but everything with matplotlib is a bit long and needs context
#here I load the previous data (before starting monitoring)
historic_data = function_to_load_history('path/to/file.log')
#then I create a plot
figure, ax = plt.subplots()
#I keep the lines in a list
lineList = []
for serie in historic_data:
line, = ax.plot(serie)
lineList.append(line)
#then I display the plot
plt.ion()
plt.show()
#and I start 'listening' for tail input in the for loop
for line in sys.stdin:
# I add the new data to the historic data
historic_data = function_to_append(line, historic_data)
#I update the plot and redraw, using the already created lines
for i,serie in enumerate(historic_data):
# OK here is the problem : here, sometimes, a new serie is discovered in the log file
# so the last series have no line associated in lineList. I test this :
# if the line exist in the line list, then no problem I update an existing line
if i < len(lineList):
lineList[i].set_data(serie)
#HERE IS THE PROBLEM : if i enconter a new serie, I add it to the plot but it is not dislayed.
else:
line, = ax.plot(serie)
lineList.append(line)
figure.gca().autoscale_view()
figure.gca().relim()
plt.draw()
I have no idea how to ask matplotlib to draw the new serie(s). Any idea ?
thank you =)
I am building an internal plugin for Sublime Text 3 to automate some changes we need done in our HTML.
I'm close to finishing it so we can start using it but I just have one small issue I can't seem to find a solution for.
The plugin will search for some specific HTML code, save them in a file and then modify the code in the view to reference some text in a json file. Then the plugin will open a new view and paste the contents of the file we saved some code in step 1. After which, I need to do some formatting in the new view (replace commas, quotes and brackets with a new line) and then run another internal sublime command in the new view.
The issue is after replacing the commas, quotes and brackets with a new line, the new view changes to an "Instant File Search" which messes with how the view runs the next command and inserts some garbage characters.
Example of the code:
#Open new tab and paste the copied subheads
newView = self.view.window().new_file(syntax="HTML.sublime-syntax")
newView.insert(edit, 0, json.dumps(sections))
# Clear any current selections in the new view
newView.sel().clear()
# Remove quotes, commas and square brackets and separate into new lines
q = newView.find_all(r"(\x{0022}\,\s\x{0022})|(\[\x{0022})|(\x{0022}\])")
for region in reversed(q):
newView.sel().add(region)
newView.replace(edit, region, "\n")
# Clear any current selections in the new view
newView.sel().clear()
q = newView.find_all("{% r")
for region in reversed(q):
newView.sel().add(region)
newView.replace(edit, region, "<p>{% r")
# Clear any current selections in the new view
newView.sel().clear()
q = newView.find_all("endreplace %}")
for region in reversed(q):
newView.sel().add(region)
newView.replace(edit, region, "endreplace %}</p>")
This is what it outputs in the new view:
If I click undo, I get the expected output which seems to mean sublime does something extra after running the last find_all code.
I haven't found anything online regarding this issue so I'm unable to try things to fix this.
Does anyone have an idea on how I should proceed?
P.S. One possible solution is to manually open a new view and run some commands but I'm trying to do all of that in 1 step using my plugin.
I have a plotly graph stored in a html file, file.html. This was created in another script using for example:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.write_html('file.html', auto_open=True)
Is there a way to open directly the html file without rewrite the plotly code?
Something like:
fig = go.read_html('file.html')
I need the plot inside the variable. For example this has to work:
fig = read html file file.html
fig.write_html('copyOfFile.html', auto_open=True)
I use both Python and R so I'd like a solution for both/one of them.
You can use python standard library webbrowser. It uses default browser to open the document.
import webbrowser
webbrowser.open('file.html')
I used the plotly streaming API from Python plot.ly/python/streaming-tutorial ) to set up a dashboard with graphs showing data streamed from local logfiles (.txt).
I followed the tutorial to create a graph of a data stream; reproducing the "Getting started" example worked fine (although i had to change the py.iplot() into py.plot()).
I made some small modifications to the working example code to get the Y-axis value from a text file on my local drive. It does manage to plot the value written in my text file on the graph and even update it as I modify the value in the text file, but it behaves differently than the graph produced by the example code for a streamed plotly graph. I include both my code for the "Example" graph and my code for the "Data from local text file" graph; and images of the different behaviors.
The first two images show the Plot and Data produced by the "Example" code and the last two for the "Data from local text file" code. : http://imgur.com/a/ugo6m
The interesting thing here is that in the first case (Example), the updated value of Y is shown on a new line in the Data tab. This is not the case in the second case (Data from local text file). In the second case, the Y value is updated, but always takes the place of the first line. Instead of adding a new Y point and storing the previous one, it just constantly modifies the first value that Y received. I think the problem comes from there.
Here's a link for both codes, they're short and only the last few lines matter, as I suppose the problem comes from there since they're the only difference between both codes. I tried different working expressions to read the value from the text file ("with open('data.txt', 'r')) but nothing does it. Does anyone know how to make it work properly?
(!!!Careful both codes run an infinite loop!!!)
"Example": http://pastebin.com/6by30ANs
"Data from local text file": see below
Thanks in advance for your time,
PS: I had to put my second code here below as I do not have enough reputation to put more than 2 links.
import plotly.plotly as py
import plotly.tools as tls
import plotly.graph_objs as go
import datetime
import time
tls.set_credentials_file(username='lo.dewaele', stream_ids = ['aqwoq4i2or'], api_key='PNASXMZQmLmAVLtthYq2')
stream_ids = tls.get_credentials_file()['stream_ids']
stream_id = stream_ids[0]
stream_1 = dict(token=stream_id, maxpoints=20)
trace1 = go.Scatter(
x=[],
y=[],
mode='lines+markers',
stream=stream_1
)
data = go.Data([trace1])
layout = go.Layout(title='Time Series')
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='stream')
s = py.Stream(stream_id)
s.open()
time.sleep(1)
while True:
graphdata = open('graphdata.txt', 'r') #open file in read mode
y = [graphdata.readline()] #read the first line of the file (just one integer)
x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
s.write(dict(x=x, y=y))
graphdata.close() #close the file
time.sleep(1)
s.close()
I try to load a cache file in Maya using a python script. I used the code snipped posted here: importing multiple cache files in Maya using Python
My code looks like this:
pm.mel.doImportCacheFile(myCachePath, "", [selectedObject], list())
myCachePath: Stores the path to the xml file
selectedObject: e.g. flameShepe1 (represents the fluid container)
First I thought that it finally worked, but whenever I press the play button and render an image again I don't get the same output. The simulation has the same shape but the colors are not the same.
When I use Fluid nCache -> Attache Existing ... everything works.
How is that possible?
Reading the attach cache command, Attaching cache to fluid is different, try :
pm.mel.doImportFluidCacheFile(pathCache, "xmlcache", ['fluid1'], [])
Hope it will do the trick !
---EDIT---
Note that you could do without pymel formating a string like this :
lineToEval = 'doImportFluidCacheFile("{0}", "xmlcache", {{"{1}"}}, {{}});'.format( pathCache, fluidsSel[0])
mel.eval(lineToEval)