When I run :
plt.hist('%s/draws.csv' % CONFIG['build']['draw_data'])
I get this weird histogram,
all my data is put under the same frequency bar, and I cannot get rid of the file path below, neither show x.ticks.
Its weird because, my data is simply a csv file exported from np.random.normal(size=100000).
When I run directly the code :
data = np.random.normal(size=10000)
plt.hist(data)
I get a normal histogram :
What could be the issue here?
Related
Configuration:
MOXA Debian 9, using Python 2.7 latest version (The software is written in Python2.7) with Matplotlib 2.2.5. The program is not in service anymore, but still works great.
Question:
I want to overlay a generated plot, on top of an png image using matplotlib. This would generate final image
Situation:
The program measures the sky brightness using a sensor and with that data it generates a plot. This every 5 minutes. The plot.py script file is used to build a plot.
I use to just overlay the plot on top of the image at the end of the night using Imagemagick overlay line with a small sh script. But as the program updates the plot every 5 minutes at night, i want to be able to already overlay the plot on top of the image, if possible using matplotlib inside the plot.py script. The plot and the image are both png.
Is this possible? I have investigated this a bit, and i think i need to add some code between line
print('Ploting photometer data ...')
if (input_filename is None):
input_filename = config.current_data_directory+\
'/'+config._device_shorttype+'_'+config._observatory_name+'.dat'
# Define the observatory in ephem
Ephem = Ephemerids()
# Get and process the data from input_filename
NSBData = SQMData(input_filename,Ephem)
# Moon and twilight ephemerids.
Ephem.calculate_moon_ephems(thedate=NSBData.Night)
Ephem.calculate_twilight(thedate=NSBData.Night)
Ephem.calculate_observation(thedate=NSBData.Night)
# Calculate data statistics
NSBData.data_statistics(Ephem)
# Write statiscs to file?
if write_stats==True:
save_stats_to_file(NSBData.Night,NSBData,Ephem)
# Plot the data and save the resulting figure
NSBPlot = Plot(NSBData,Ephem)
Above is the plot generated, and here i think i would need to overlay it before it will be saved as quoted below.
output_filenames = [\
str("%s/%s_%s.png" %(config.current_data_directory,\
config._device_shorttype,config._observatory_name)),\
str("%s/%s_120000_%s-%s.png" \
%(config.daily_graph_directory, str(NSBData.Night).replace('-',''),\
config._device_shorttype, config._observatory_name))\
]
for output_filename in output_filenames:
NSBPlot.save_figure(output_filename)
Is this correct, and how do i do this?
I have found some information: test.png would then be ofcourse the destination location of the image.png. But to be honest, do not know where to start and how to interpreted it.I have read error's of people using plt.show() in the end, but that freezes the system, so i do not need that line.
import matplotlib.pyplot as plt
im = plt.imread('test.png')
implot = plt.imshow(im)
plt.plot([100,200,300],[200,150,200],'o')
Thank you in advance.
I'm trying out Datashader on Google Colab to visualise a large dataset of longitudes and latitudes colored logarithmically with the colorcet.fire colormaps, but my code throws a completely blank output.
Code in text:
import datashader as ds
import pandas as pd
import colorcet
data = pd.read_csv('hab.csv', usecols=['longitude','latitude'])
cvs = ds.Canvas()
agg = cvs.points(data, 'latitude', 'longitude')
ds.tf.set_background(ds.tf.shade(agg, cmap=colorcet.fire, how='log'))
What I see on Colab:
I'm not a collab user, but yes, when I run your code locally with the five datapoints shown I get a blank plot. In my local version, it's because the code is specifying a colormap whose highest value is white, and for a few scattered points each of them are at the highest value. The code uses set_background, perhaps trying to set the background to black as would be suitable for that colormap, but it doesn't specify "black" and so the set_background call does nothing. If I specify the background color and add Datashader spreading so that these single datapoints are easier to see, I do get a plot from your code:
cvs = ds.Canvas()
agg = cvs.points(data, 'latitude', 'longitude')
ds.tf.set_background(ds.tf.shade(ds.tf.spread(agg, px=10), cmap=colorcet.fire, how='log'), "black")
You may have some other problem as well, though, since the plot you showed wasn't just white, it appeared to be transparent. And if your dataset is indeed large, you should see output anyway, because data points would then overlap and use all the colors in the colormap.
I am generating histograms using go.Histogram as described here. I am getting what is expected:
What I want to do is to show some statistics of the selected data, as shown in the next image (the white box I added manually in Paint):
I have tried this and within the function selection_fn I placed the add_annotation described here. However, it does nothing. No errors too.
How can I do this?
Edit: I am using this code taken from this link
import plotly.graph_objects as go
import numpy as np
x = np.random.randn(500)
fig = go.Figure(data=[go.Histogram(x=x)])
fig.show()
with obviously another data set.
I'm working on taking some data from a dataset and plotting certain aspects of it. Here's my code below:
import matplotlib.pyplot as plt
df1 = pd.read_csv('dataset_1.csv')
soil_moisture = list(df1.Soil_Moisture)
soil_temperature = list(df1.Soil_Temp)
print(len(soil_moisture))
print(len(soil_temperature))
plt.plot([soil_moisture], [soil_temperature])
plt.show()
As you can see, it takes data from each of those columns and tries to make a line graph. However, when I run, it just displays an empty graph. This is weird since when I print the soil_moisture and soil_temperature, it tells me that there's actual data, and none of my other plots in the same notebook are experiencing this. All help is appreciated!
Here's an image of the jupyter output
Please revise line 7 of your code as:
plt.plot(soil_moisture, soil_temperature)
When you use [soil_moisture] that means you are generating another list with list soil_moisture as its first element.
I'm trying to produce a dashboard with plotly, wherein the graphs are sourced off a loaded dataframe. My problem currently is that upon creating a bar chart, the output is blank, even when I use a line chart, it works fine.
Here is a preview of my dataset:
It's a grouped-by object, I essentially have a larger dataset that I wanted topline figures for showing topline time series trends.
preview of my dataset
data set types
import plotly.offline as offline
import plotly.graph_objs as go
data = [go.Bar(
x=[Safe.Period],
y=[Safe.Units]
)]
pl.offline.iplot(data, filename='basic-bar')
To which I get this blank output:
blank output
Now I've got it to work like this:
trace = go.Scatter(x= Topline.Period,
y= Topline.Units,
mode = "lines")
data = [trace]
pl.offline.iplot({"data":data})
Line chart
So in a line chart, or at least a scatter connected by lines, the code works. but not when its done as a bar chart.
Can anybody shed some light on this/ recommend any fixes/checks? I'm still getting accustomed to plotly and hope to one day move my excel dashboarding into python/plotly.