Seaborn plot - chronological order2019 Community Moderator ElectionPlot two graphs in same plot in RHow to put the legend out of the plotSave plot to image file instead of displaying it using MatplotlibHow to change the order of DataFrame columns?Seaborn plots not showing upPandas rename column names with certain patterns and do aggregationSeaborn stripplot of datetime objects not workingPlot Pandas Dataframe with Seabornselenium pandas dataframe constructor not properly calledLinePlot with Seaborn: View Limit Minimum Error

Generating a list with duplicate entries

Is this Paypal Github SDK reference really a dangerous site?

Can I challenge the interviewer to give me a proper technical feedback?

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

Insult for someone who "doesn't know anything"

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

How to educate team mate to take screenshots for bugs with out unwanted stuff

Create chunks from an array

Is it a Cyclops number? "Nobody" knows!

The (Easy) Road to Code

Boss Telling direct supervisor I snitched

Mixed Feelings - What am I

direct sum of representation of product groups

Why isn't P and P/poly trivially the same?

Giving a talk in my old university, how prominently should I tell students my salary?

What exactly is the meaning of "fine wine"?

Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?

Why restrict private health insurance?

Limpar string com Regex

Use Mercury as quenching liquid for swords?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Rationale to prefer local variables over instance variables?

What would be the most expensive material to an intergalactic society?

What do you call someone who likes to pick fights?



Seaborn plot - chronological order



2019 Community Moderator ElectionPlot two graphs in same plot in RHow to put the legend out of the plotSave plot to image file instead of displaying it using MatplotlibHow to change the order of DataFrame columns?Seaborn plots not showing upPandas rename column names with certain patterns and do aggregationSeaborn stripplot of datetime objects not workingPlot Pandas Dataframe with Seabornselenium pandas dataframe constructor not properly calledLinePlot with Seaborn: View Limit Minimum Error










0















I have such a Seaborn spaghetti plot from dataframe. As you can see - the dates (in form of string; the first column is the dates of acq; the other - different research sites of measurment) are shuffled and I would like to put them chronologically like in the dataframe. I was looking for some hint on web, but not successful.



enter image description here



Here's my important part of code:



# library and packeges
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import pandas as pd
import numpy as np
import seaborn as sns
import os
from datetime import datetime


# Data test set for year 2015; 8 rapeseed fields.
data = 'Date' : ['3-Mar', '20-Mar', '20-Apr', '21-Apr', '29-Apr', '7-May', '30-May', '31-May', '7-Jun', '16-Jun',
'1-Jul', '2-Jul', '10-Jul'],
'Field_1' : [0.5840, 0.8159, 0.7789, 0.7665, 0.8510, 0.7428, 'mraky', 0.6820, 0.8714, 0.8902, 'mraky', 0.8289, 0.6877],
'Field_2' : [0.6196, 0.8291, 0.7686, 0.7848, 0.9935, 0.7406, 'mraky', 0.6952, 0.6952, 0.6952, 'mraky', 0.8119, 'mraky'],
'Field_3' : [0.6790, 0.9220, 0.8380, 0.8312, 'mraky', 0.7398, 'mraky', 0.7019, 0.7985, 0.8941, 0.6430, 0.7891, 'mraky'],
'Field_4' : [0.5570, 0.8285, 0.8084, 0.8340, 0.9095, 'mraky', 'mraky', 0.6675, 0.8648, 0.9536, 0.7933, 0.7641, 0.6566],
'Field_5' : [0.6085, 0.8404, 0.8036, 0.8009, 'mraky', 0.7811, 0.5960, 0.6685, 0.8815, 'mraky', 'mraky', 0.8438, 0.6959],
'Field_6' : [0.5187, 0.7611, 0.7920, 0.7935, 0.8554, 0.7151, 0.7929, 0.6657, 0.8697, 0.8842, 0.8055, 0.8304, 0.6531],
'Field_7' : [0.4110, 0.5756, 0.5911, 0.5538, 0.6688, 0.7373, 0.6962, 0.6345, 0.8210, 0.8376, 0.7750, 0.8033, 0.5736],
'Field_8' : [0.5225, 0.7648, 0.5691, 0.6819, 0.8134, 'mraky', 0.7281, 0.6799, 0.8590, 0.8786, 'mraky', 0.8475, 0.7056]


# Data set will be corrected. The string values will changed to None values.
def replace_string_with_None(data, value_to_find, value_for_replacing):
for key, value in data.items():
data[key] = [value_for_replacing if i == value_to_find else i for i in value]
return data
data = replace_string_with_None(data, "mraky", None)
print(data)


# Pandas DataFrame
frame = pd.DataFrame(data)
print(frame)
# Date string altered to Datetime
frame['Date'] = pd.to_datetime(frame['Date'], format='%d-%b', errors='ignore')
frame['Date'] = frame['Date'].apply(lambda x: x.strftime('%d-%b'))
print(frame)

# Seaborn lineplot style and aesthetics.
sns.set_style('whitegrid')
sns.set(rc='figure.figsize':(11.7,8.27))
sns.set_context("talk", rc="lines.linewidth": 3)


num = 0
for column in frame.drop('Date', axis=1):
num += 1
result = sns.lineplot(x = 'Date', y = frame[column], data = frame, marker='o', palette = flatui)
result.set_xlabel('Date of acquisition', fontsize= 20)
result.set_ylabel('NDVI value', fontsize= 20)
result.set_title('Time series of NDVI', fontsize = 22)
plt.xticks(rotation = 45)
plt.show()
plt.savefig('myfile.pdf')


Thanks!










share|improve this question
























  • You need to convert your strings to datetimes, e.g. pd.to_datetime().

    – ImportanceOfBeingErnest
    2 days ago











  • Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

    – Lukáš Tůma
    2 days ago












  • Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

    – ImportanceOfBeingErnest
    2 days ago












  • Okey. I see, but I need only month and day in my plot. Is it possible?

    – Lukáš Tůma
    2 days ago











  • You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

    – ImportanceOfBeingErnest
    2 days ago















0















I have such a Seaborn spaghetti plot from dataframe. As you can see - the dates (in form of string; the first column is the dates of acq; the other - different research sites of measurment) are shuffled and I would like to put them chronologically like in the dataframe. I was looking for some hint on web, but not successful.



enter image description here



Here's my important part of code:



# library and packeges
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import pandas as pd
import numpy as np
import seaborn as sns
import os
from datetime import datetime


# Data test set for year 2015; 8 rapeseed fields.
data = 'Date' : ['3-Mar', '20-Mar', '20-Apr', '21-Apr', '29-Apr', '7-May', '30-May', '31-May', '7-Jun', '16-Jun',
'1-Jul', '2-Jul', '10-Jul'],
'Field_1' : [0.5840, 0.8159, 0.7789, 0.7665, 0.8510, 0.7428, 'mraky', 0.6820, 0.8714, 0.8902, 'mraky', 0.8289, 0.6877],
'Field_2' : [0.6196, 0.8291, 0.7686, 0.7848, 0.9935, 0.7406, 'mraky', 0.6952, 0.6952, 0.6952, 'mraky', 0.8119, 'mraky'],
'Field_3' : [0.6790, 0.9220, 0.8380, 0.8312, 'mraky', 0.7398, 'mraky', 0.7019, 0.7985, 0.8941, 0.6430, 0.7891, 'mraky'],
'Field_4' : [0.5570, 0.8285, 0.8084, 0.8340, 0.9095, 'mraky', 'mraky', 0.6675, 0.8648, 0.9536, 0.7933, 0.7641, 0.6566],
'Field_5' : [0.6085, 0.8404, 0.8036, 0.8009, 'mraky', 0.7811, 0.5960, 0.6685, 0.8815, 'mraky', 'mraky', 0.8438, 0.6959],
'Field_6' : [0.5187, 0.7611, 0.7920, 0.7935, 0.8554, 0.7151, 0.7929, 0.6657, 0.8697, 0.8842, 0.8055, 0.8304, 0.6531],
'Field_7' : [0.4110, 0.5756, 0.5911, 0.5538, 0.6688, 0.7373, 0.6962, 0.6345, 0.8210, 0.8376, 0.7750, 0.8033, 0.5736],
'Field_8' : [0.5225, 0.7648, 0.5691, 0.6819, 0.8134, 'mraky', 0.7281, 0.6799, 0.8590, 0.8786, 'mraky', 0.8475, 0.7056]


# Data set will be corrected. The string values will changed to None values.
def replace_string_with_None(data, value_to_find, value_for_replacing):
for key, value in data.items():
data[key] = [value_for_replacing if i == value_to_find else i for i in value]
return data
data = replace_string_with_None(data, "mraky", None)
print(data)


# Pandas DataFrame
frame = pd.DataFrame(data)
print(frame)
# Date string altered to Datetime
frame['Date'] = pd.to_datetime(frame['Date'], format='%d-%b', errors='ignore')
frame['Date'] = frame['Date'].apply(lambda x: x.strftime('%d-%b'))
print(frame)

# Seaborn lineplot style and aesthetics.
sns.set_style('whitegrid')
sns.set(rc='figure.figsize':(11.7,8.27))
sns.set_context("talk", rc="lines.linewidth": 3)


num = 0
for column in frame.drop('Date', axis=1):
num += 1
result = sns.lineplot(x = 'Date', y = frame[column], data = frame, marker='o', palette = flatui)
result.set_xlabel('Date of acquisition', fontsize= 20)
result.set_ylabel('NDVI value', fontsize= 20)
result.set_title('Time series of NDVI', fontsize = 22)
plt.xticks(rotation = 45)
plt.show()
plt.savefig('myfile.pdf')


Thanks!










share|improve this question
























  • You need to convert your strings to datetimes, e.g. pd.to_datetime().

    – ImportanceOfBeingErnest
    2 days ago











  • Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

    – Lukáš Tůma
    2 days ago












  • Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

    – ImportanceOfBeingErnest
    2 days ago












  • Okey. I see, but I need only month and day in my plot. Is it possible?

    – Lukáš Tůma
    2 days ago











  • You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

    – ImportanceOfBeingErnest
    2 days ago













0












0








0








I have such a Seaborn spaghetti plot from dataframe. As you can see - the dates (in form of string; the first column is the dates of acq; the other - different research sites of measurment) are shuffled and I would like to put them chronologically like in the dataframe. I was looking for some hint on web, but not successful.



enter image description here



Here's my important part of code:



# library and packeges
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import pandas as pd
import numpy as np
import seaborn as sns
import os
from datetime import datetime


# Data test set for year 2015; 8 rapeseed fields.
data = 'Date' : ['3-Mar', '20-Mar', '20-Apr', '21-Apr', '29-Apr', '7-May', '30-May', '31-May', '7-Jun', '16-Jun',
'1-Jul', '2-Jul', '10-Jul'],
'Field_1' : [0.5840, 0.8159, 0.7789, 0.7665, 0.8510, 0.7428, 'mraky', 0.6820, 0.8714, 0.8902, 'mraky', 0.8289, 0.6877],
'Field_2' : [0.6196, 0.8291, 0.7686, 0.7848, 0.9935, 0.7406, 'mraky', 0.6952, 0.6952, 0.6952, 'mraky', 0.8119, 'mraky'],
'Field_3' : [0.6790, 0.9220, 0.8380, 0.8312, 'mraky', 0.7398, 'mraky', 0.7019, 0.7985, 0.8941, 0.6430, 0.7891, 'mraky'],
'Field_4' : [0.5570, 0.8285, 0.8084, 0.8340, 0.9095, 'mraky', 'mraky', 0.6675, 0.8648, 0.9536, 0.7933, 0.7641, 0.6566],
'Field_5' : [0.6085, 0.8404, 0.8036, 0.8009, 'mraky', 0.7811, 0.5960, 0.6685, 0.8815, 'mraky', 'mraky', 0.8438, 0.6959],
'Field_6' : [0.5187, 0.7611, 0.7920, 0.7935, 0.8554, 0.7151, 0.7929, 0.6657, 0.8697, 0.8842, 0.8055, 0.8304, 0.6531],
'Field_7' : [0.4110, 0.5756, 0.5911, 0.5538, 0.6688, 0.7373, 0.6962, 0.6345, 0.8210, 0.8376, 0.7750, 0.8033, 0.5736],
'Field_8' : [0.5225, 0.7648, 0.5691, 0.6819, 0.8134, 'mraky', 0.7281, 0.6799, 0.8590, 0.8786, 'mraky', 0.8475, 0.7056]


# Data set will be corrected. The string values will changed to None values.
def replace_string_with_None(data, value_to_find, value_for_replacing):
for key, value in data.items():
data[key] = [value_for_replacing if i == value_to_find else i for i in value]
return data
data = replace_string_with_None(data, "mraky", None)
print(data)


# Pandas DataFrame
frame = pd.DataFrame(data)
print(frame)
# Date string altered to Datetime
frame['Date'] = pd.to_datetime(frame['Date'], format='%d-%b', errors='ignore')
frame['Date'] = frame['Date'].apply(lambda x: x.strftime('%d-%b'))
print(frame)

# Seaborn lineplot style and aesthetics.
sns.set_style('whitegrid')
sns.set(rc='figure.figsize':(11.7,8.27))
sns.set_context("talk", rc="lines.linewidth": 3)


num = 0
for column in frame.drop('Date', axis=1):
num += 1
result = sns.lineplot(x = 'Date', y = frame[column], data = frame, marker='o', palette = flatui)
result.set_xlabel('Date of acquisition', fontsize= 20)
result.set_ylabel('NDVI value', fontsize= 20)
result.set_title('Time series of NDVI', fontsize = 22)
plt.xticks(rotation = 45)
plt.show()
plt.savefig('myfile.pdf')


Thanks!










share|improve this question
















I have such a Seaborn spaghetti plot from dataframe. As you can see - the dates (in form of string; the first column is the dates of acq; the other - different research sites of measurment) are shuffled and I would like to put them chronologically like in the dataframe. I was looking for some hint on web, but not successful.



enter image description here



Here's my important part of code:



# library and packeges
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import pandas as pd
import numpy as np
import seaborn as sns
import os
from datetime import datetime


# Data test set for year 2015; 8 rapeseed fields.
data = 'Date' : ['3-Mar', '20-Mar', '20-Apr', '21-Apr', '29-Apr', '7-May', '30-May', '31-May', '7-Jun', '16-Jun',
'1-Jul', '2-Jul', '10-Jul'],
'Field_1' : [0.5840, 0.8159, 0.7789, 0.7665, 0.8510, 0.7428, 'mraky', 0.6820, 0.8714, 0.8902, 'mraky', 0.8289, 0.6877],
'Field_2' : [0.6196, 0.8291, 0.7686, 0.7848, 0.9935, 0.7406, 'mraky', 0.6952, 0.6952, 0.6952, 'mraky', 0.8119, 'mraky'],
'Field_3' : [0.6790, 0.9220, 0.8380, 0.8312, 'mraky', 0.7398, 'mraky', 0.7019, 0.7985, 0.8941, 0.6430, 0.7891, 'mraky'],
'Field_4' : [0.5570, 0.8285, 0.8084, 0.8340, 0.9095, 'mraky', 'mraky', 0.6675, 0.8648, 0.9536, 0.7933, 0.7641, 0.6566],
'Field_5' : [0.6085, 0.8404, 0.8036, 0.8009, 'mraky', 0.7811, 0.5960, 0.6685, 0.8815, 'mraky', 'mraky', 0.8438, 0.6959],
'Field_6' : [0.5187, 0.7611, 0.7920, 0.7935, 0.8554, 0.7151, 0.7929, 0.6657, 0.8697, 0.8842, 0.8055, 0.8304, 0.6531],
'Field_7' : [0.4110, 0.5756, 0.5911, 0.5538, 0.6688, 0.7373, 0.6962, 0.6345, 0.8210, 0.8376, 0.7750, 0.8033, 0.5736],
'Field_8' : [0.5225, 0.7648, 0.5691, 0.6819, 0.8134, 'mraky', 0.7281, 0.6799, 0.8590, 0.8786, 'mraky', 0.8475, 0.7056]


# Data set will be corrected. The string values will changed to None values.
def replace_string_with_None(data, value_to_find, value_for_replacing):
for key, value in data.items():
data[key] = [value_for_replacing if i == value_to_find else i for i in value]
return data
data = replace_string_with_None(data, "mraky", None)
print(data)


# Pandas DataFrame
frame = pd.DataFrame(data)
print(frame)
# Date string altered to Datetime
frame['Date'] = pd.to_datetime(frame['Date'], format='%d-%b', errors='ignore')
frame['Date'] = frame['Date'].apply(lambda x: x.strftime('%d-%b'))
print(frame)

# Seaborn lineplot style and aesthetics.
sns.set_style('whitegrid')
sns.set(rc='figure.figsize':(11.7,8.27))
sns.set_context("talk", rc="lines.linewidth": 3)


num = 0
for column in frame.drop('Date', axis=1):
num += 1
result = sns.lineplot(x = 'Date', y = frame[column], data = frame, marker='o', palette = flatui)
result.set_xlabel('Date of acquisition', fontsize= 20)
result.set_ylabel('NDVI value', fontsize= 20)
result.set_title('Time series of NDVI', fontsize = 22)
plt.xticks(rotation = 45)
plt.show()
plt.savefig('myfile.pdf')


Thanks!







python dataframe plot seaborn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







Lukáš Tůma

















asked 2 days ago









Lukáš TůmaLukáš Tůma

143




143












  • You need to convert your strings to datetimes, e.g. pd.to_datetime().

    – ImportanceOfBeingErnest
    2 days ago











  • Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

    – Lukáš Tůma
    2 days ago












  • Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

    – ImportanceOfBeingErnest
    2 days ago












  • Okey. I see, but I need only month and day in my plot. Is it possible?

    – Lukáš Tůma
    2 days ago











  • You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

    – ImportanceOfBeingErnest
    2 days ago

















  • You need to convert your strings to datetimes, e.g. pd.to_datetime().

    – ImportanceOfBeingErnest
    2 days ago











  • Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

    – Lukáš Tůma
    2 days ago












  • Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

    – ImportanceOfBeingErnest
    2 days ago












  • Okey. I see, but I need only month and day in my plot. Is it possible?

    – Lukáš Tůma
    2 days ago











  • You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

    – ImportanceOfBeingErnest
    2 days ago
















You need to convert your strings to datetimes, e.g. pd.to_datetime().

– ImportanceOfBeingErnest
2 days ago





You need to convert your strings to datetimes, e.g. pd.to_datetime().

– ImportanceOfBeingErnest
2 days ago













Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

– Lukáš Tůma
2 days ago






Nope after pd.to_datetime and strftime, result is same or little bit different but still not ordered chronologically. :-(

– Lukáš Tůma
2 days ago














Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

– ImportanceOfBeingErnest
2 days ago






Sure, strftime converts back to a string, which is what you should avoid. Note that you may of course provide a Minimal, Complete, and Verifiable example, which would allow someone to actually answer this question.

– ImportanceOfBeingErnest
2 days ago














Okey. I see, but I need only month and day in my plot. Is it possible?

– Lukáš Tůma
2 days ago





Okey. I see, but I need only month and day in my plot. Is it possible?

– Lukáš Tůma
2 days ago













You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

– ImportanceOfBeingErnest
2 days ago





You need to distinguish between the position in the plot and the text labels you want to show. Changing the format of the text labels is possible once you have the correct plot.

– ImportanceOfBeingErnest
2 days ago












0






active

oldest

votes











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023216%2fseaborn-plot-chronological-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023216%2fseaborn-plot-chronological-order%23new-answer', 'question_page');

);

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







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко