Line-graph plotting strangely; scatter plot rejects timestamp
I'm plotting some data imported from a csv file; a simple line graph works ok except that there are messy-looking lines where the data points connect (they're angled oddly and give the graph an overall cluttered look).
I want to change to a scatter-plot with lines between the points, hoping that this will remove the issue. However, when I plot a scatter-plot, the datetime from my csv is rejected and the following error message is displayed.
Does anyone have any ideas how I can use csv datetime with a scatter-plot. Or, even better, how I can stop those annoying messy lines in a line-graph? This latter would be the ideal option.
Error message for the .values solution...
My code is below:
import matplotlib.pyplot as plt
import pandas as pd
import os
import matplotlib.dates as mdates
# Read the file in csv
File = pd.read_csv("Timeline.csv")
# Where to save the output
outputDirectory = 'Z:\15_Hawaii\Plotting\'
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
# Datetime selection
time = File.iloc[:,0]
time_time = pd.to_datetime(time, format = '%m/%d/%Y')
time_time = pd.to_datetime(time_time, format = '%m/%d/%Y')
time_day = mdates.DayLocator()
# Kona data selection
Kona = File.iloc[:,2]
# defining the names which will be called
fig, host = plt.subplots()
ax = plt.gca()
# simple plot of the data
K_plot, = host.plot(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# attempt to scatter plot the data
K_plot, = plt.scatter(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# other plotting parameters
ax.xaxis.grid(linestyle='dotted')
plt.setp(ax.xaxis.get_majorticklabels(), rotation=80 )
fig.set_size_inches(12, 5)
plt.savefig(outputDirectory + 'SO2_PLOT_1' + '.png', bbox_inches='tight', dpi=300, pad_inches=0.0)
csv matplotlib timestamp scatter-plot linegraph
add a comment |
I'm plotting some data imported from a csv file; a simple line graph works ok except that there are messy-looking lines where the data points connect (they're angled oddly and give the graph an overall cluttered look).
I want to change to a scatter-plot with lines between the points, hoping that this will remove the issue. However, when I plot a scatter-plot, the datetime from my csv is rejected and the following error message is displayed.
Does anyone have any ideas how I can use csv datetime with a scatter-plot. Or, even better, how I can stop those annoying messy lines in a line-graph? This latter would be the ideal option.
Error message for the .values solution...
My code is below:
import matplotlib.pyplot as plt
import pandas as pd
import os
import matplotlib.dates as mdates
# Read the file in csv
File = pd.read_csv("Timeline.csv")
# Where to save the output
outputDirectory = 'Z:\15_Hawaii\Plotting\'
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
# Datetime selection
time = File.iloc[:,0]
time_time = pd.to_datetime(time, format = '%m/%d/%Y')
time_time = pd.to_datetime(time_time, format = '%m/%d/%Y')
time_day = mdates.DayLocator()
# Kona data selection
Kona = File.iloc[:,2]
# defining the names which will be called
fig, host = plt.subplots()
ax = plt.gca()
# simple plot of the data
K_plot, = host.plot(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# attempt to scatter plot the data
K_plot, = plt.scatter(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# other plotting parameters
ax.xaxis.grid(linestyle='dotted')
plt.setp(ax.xaxis.get_majorticklabels(), rotation=80 )
fig.set_size_inches(12, 5)
plt.savefig(outputDirectory + 'SO2_PLOT_1' + '.png', bbox_inches='tight', dpi=300, pad_inches=0.0)
csv matplotlib timestamp scatter-plot linegraph
Can you tryK_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?
– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
There is no comma afterK_plot
in my suggestion.
– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33
add a comment |
I'm plotting some data imported from a csv file; a simple line graph works ok except that there are messy-looking lines where the data points connect (they're angled oddly and give the graph an overall cluttered look).
I want to change to a scatter-plot with lines between the points, hoping that this will remove the issue. However, when I plot a scatter-plot, the datetime from my csv is rejected and the following error message is displayed.
Does anyone have any ideas how I can use csv datetime with a scatter-plot. Or, even better, how I can stop those annoying messy lines in a line-graph? This latter would be the ideal option.
Error message for the .values solution...
My code is below:
import matplotlib.pyplot as plt
import pandas as pd
import os
import matplotlib.dates as mdates
# Read the file in csv
File = pd.read_csv("Timeline.csv")
# Where to save the output
outputDirectory = 'Z:\15_Hawaii\Plotting\'
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
# Datetime selection
time = File.iloc[:,0]
time_time = pd.to_datetime(time, format = '%m/%d/%Y')
time_time = pd.to_datetime(time_time, format = '%m/%d/%Y')
time_day = mdates.DayLocator()
# Kona data selection
Kona = File.iloc[:,2]
# defining the names which will be called
fig, host = plt.subplots()
ax = plt.gca()
# simple plot of the data
K_plot, = host.plot(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# attempt to scatter plot the data
K_plot, = plt.scatter(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# other plotting parameters
ax.xaxis.grid(linestyle='dotted')
plt.setp(ax.xaxis.get_majorticklabels(), rotation=80 )
fig.set_size_inches(12, 5)
plt.savefig(outputDirectory + 'SO2_PLOT_1' + '.png', bbox_inches='tight', dpi=300, pad_inches=0.0)
csv matplotlib timestamp scatter-plot linegraph
I'm plotting some data imported from a csv file; a simple line graph works ok except that there are messy-looking lines where the data points connect (they're angled oddly and give the graph an overall cluttered look).
I want to change to a scatter-plot with lines between the points, hoping that this will remove the issue. However, when I plot a scatter-plot, the datetime from my csv is rejected and the following error message is displayed.
Does anyone have any ideas how I can use csv datetime with a scatter-plot. Or, even better, how I can stop those annoying messy lines in a line-graph? This latter would be the ideal option.
Error message for the .values solution...
My code is below:
import matplotlib.pyplot as plt
import pandas as pd
import os
import matplotlib.dates as mdates
# Read the file in csv
File = pd.read_csv("Timeline.csv")
# Where to save the output
outputDirectory = 'Z:\15_Hawaii\Plotting\'
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
# Datetime selection
time = File.iloc[:,0]
time_time = pd.to_datetime(time, format = '%m/%d/%Y')
time_time = pd.to_datetime(time_time, format = '%m/%d/%Y')
time_day = mdates.DayLocator()
# Kona data selection
Kona = File.iloc[:,2]
# defining the names which will be called
fig, host = plt.subplots()
ax = plt.gca()
# simple plot of the data
K_plot, = host.plot(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# attempt to scatter plot the data
K_plot, = plt.scatter(time_time, Kona, color=[0,0.690196078,0.941176471], linewidth=1, label="Kona")
# other plotting parameters
ax.xaxis.grid(linestyle='dotted')
plt.setp(ax.xaxis.get_majorticklabels(), rotation=80 )
fig.set_size_inches(12, 5)
plt.savefig(outputDirectory + 'SO2_PLOT_1' + '.png', bbox_inches='tight', dpi=300, pad_inches=0.0)
csv matplotlib timestamp scatter-plot linegraph
csv matplotlib timestamp scatter-plot linegraph
edited Nov 14 '18 at 8:23
RCW_8
asked Nov 13 '18 at 17:57
RCW_8RCW_8
146
146
Can you tryK_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?
– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
There is no comma afterK_plot
in my suggestion.
– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33
add a comment |
Can you tryK_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?
– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
There is no comma afterK_plot
in my suggestion.
– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33
Can you try
K_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Can you try
K_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
There is no comma after
K_plot
in my suggestion.– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
There is no comma after
K_plot
in my suggestion.– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33
add a comment |
1 Answer
1
active
oldest
votes
It seems that, from the image, your imported dataframe's first row contains the strings 'Date', 'Time' and 'Kona_data'. If you read from the second row like this, then does the problem persist?
time = File.iloc[1:,0]
Kona = File.iloc[1:,2]
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286929%2fline-graph-plotting-strangely-scatter-plot-rejects-timestamp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems that, from the image, your imported dataframe's first row contains the strings 'Date', 'Time' and 'Kona_data'. If you read from the second row like this, then does the problem persist?
time = File.iloc[1:,0]
Kona = File.iloc[1:,2]
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
add a comment |
It seems that, from the image, your imported dataframe's first row contains the strings 'Date', 'Time' and 'Kona_data'. If you read from the second row like this, then does the problem persist?
time = File.iloc[1:,0]
Kona = File.iloc[1:,2]
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
add a comment |
It seems that, from the image, your imported dataframe's first row contains the strings 'Date', 'Time' and 'Kona_data'. If you read from the second row like this, then does the problem persist?
time = File.iloc[1:,0]
Kona = File.iloc[1:,2]
It seems that, from the image, your imported dataframe's first row contains the strings 'Date', 'Time' and 'Kona_data'. If you read from the second row like this, then does the problem persist?
time = File.iloc[1:,0]
Kona = File.iloc[1:,2]
answered Nov 13 '18 at 18:40
anotheroneanotherone
409417
409417
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
add a comment |
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
Hi Anotherone, unfortunately removing the csv headers doesn't seem to have any effect on the scatter plot, the "invalid type promotion" error is still displayed. :(
– RCW_8
Nov 14 '18 at 8:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286929%2fline-graph-plotting-strangely-scatter-plot-rejects-timestamp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you try
K_plot = plt.scatter(time_time.values, Kona.values, color=[0,0.690196078,0.941176471], label="Kona")
?– ImportanceOfBeingErnest
Nov 13 '18 at 20:25
Hi ImportanceOfBeingErnest, when I add in .values to the scatter variables, it does produce a scatter plot, but with the TypeError "PathCollection" is not iterable. I'll add a screenshot of this to my original post so you can see...
– RCW_8
Nov 14 '18 at 8:20
There is no comma after
K_plot
in my suggestion.– ImportanceOfBeingErnest
Nov 14 '18 at 9:12
Ah! I missed that, but it seems to have fixed it! Thanks so much!
– RCW_8
Nov 14 '18 at 10:33