一款景点的日期代码

本文介绍了一个基于HTML和JavaScript实现的日历插件,该插件能够动态展示指定月份的日历,并提供日期选择功能。通过简单的JavaScript算法实现了日历布局的自动生成,包括对特殊日期的标记。
 <html>
<head>
<title>Agenda</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
BODY {
FONT-SIZE: 9pt; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px;
}
A {
FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000
}
A:hover {
TEXT-DECORATION: none; color: #000000
}
A:link {
TEXT-DECORATION: none
}
A:visited {
TEXT-DECORATION: none
}
BR {
FONT-SIZE: 9pt; height: 15pt;
}
TD {
FONT-SIZE: 9pt; LINE-HEIGHT: 11pt;
}
input {
FONT-SIZE: 9pt; height: 15pt;
}
.SCROLLBAR {
SCROLLBAR-FACE-COLOR: #718698;
SCROLLBAR-HIGHLIGHT-COLOR: #899aa9;
SCROLLBAR-SHADOW-COLOR: #506981;
SCROLLBAR-3DLIGHT-COLOR: #5b7086;
SCROLLBAR-ARROW-COLOR: #506981;
SCROLLBAR-TRACK-COLOR: #5b7086;
SCROLLBAR-DARKSHADOW-COLOR: #5b7086
}
</style>
<script language="JavaScript1.2">
<!--
var Timer = new Date();
var years = Timer.getYear();
var months = (Timer.getMonth()+1);
var days = Timer.getDate();
var weeks = Timer.getDay();
var Rec_List = "";
Rec_List = ",20020202,20020608,20020815,20021219,20010125,20011105,2001706,20030715,20031203,20030416,";

function GetDays(the_year,the_month){
var Max_day = 31;
if (the_month==4 || the_month==6 || the_month==9 || the_month==11){
Max_day = 30;
}else if(the_month==2){
if(the_year%400==0){
Max_day = 29;
}else if(the_year%100==0){
Max_day = 28;
}else if(the_year%4==0){
Max_day = 29;
}else{
Max_day = 28;
}
}
return Max_day;
}

function ShowPlan(the_year,the_month,the_day){
var thisDate = the_year + "-" + (the_month+1) + "-" + the_day;
selDate.value=thisDate;
selDate.innerText=thisDate;
LayerDate.style.visibility='hidden';
}

function HideDate(){
if(LayerDate.style.visibility!='hidden'){
LayerDate.style.visibility='hidden';
}
}

function Calendar(the_year,the_month){
var i = 0;
var FontColor;
var DateStr;
var New_Date = new Date(the_year,the_month,1)
var the_week = New_Date.getDay();
var Max_day = GetDays(the_year,the_month+1)
var dummy = 7-(the_week+Max_day)%7;
var Cal_str = "";
Cal_str += "<table align=center width=100% border=0 cellpadding=1 cellspacing=1 bgcolor=#FF9900>";
Cal_str += "<tr bgcolor=#ffcc99>";
Cal_str += "<td width=14% align=center>星期日</td>";
Cal_str += "<td width=14% align=center>星期一</td>";
Cal_str += "<td width=14% align=center>星期二</td>";
Cal_str += "<td width=14% align=center>星期三</td>";
Cal_str += "<td width=14% align=center>星期四</td>";
Cal_str += "<td width=14% align=center>星期五</td>";
Cal_str += "<td width=14% align=center>星期六</td>";
Cal_str += "</tr><tr>\n";
for(i=0;i<the_week;i++){
Cal_str += "<td valign=top align=center bgcolor=#ffffff onmouseout=this.bgColor='#ffffff' onmouseover=this.bgColor='#f2f8ff'> </td>\n";
}
for(i=1;i<=Max_day;i++){
FontColor = ((i+the_week)%7==1||(i+the_week)%7==0)?"red":"black"
DateStr = "," + the_year + (the_month<9?("0"+(parseInt(the_month)+1)):(parseInt(the_month)+1)) + (i<10?("0"+i):i) + ",";
Cal_str += "<td valign=top align=center bgcolor=" + (Rec_List.search(DateStr)!=-1?"#FFCC33":"white") + ((i==days&&the_year==years&&the_month==months-1)?" background=image/now.gif":"") + " onmouseout=this.bgColor='" + (Rec_List.search(DateStr)!=-1?"#FFCC33":"#ffffff") + "' onmouseover=this.bgColor='#f2f8ff'>"
Cal_str += "<a href=javascript:ShowPlan(" + the_year + "," + the_month + "," + i + ") style='color: " + FontColor + ";'>" + i + "</a></td>\n";
if((the_week+i)%7==0 && i!=Max_day) Cal_str += "</tr><tr>\n";
}
if(dummy < 7){
for(i=1;i<=dummy;i++){
Cal_str += "<td valign=top align=center bgcolor=#ffffff onmouseout=this.bgColor='#ffffff' onmouseover=this.bgColor='#f2f8ff'> </td>\n";
}
}
Cal_str += "</tr></table>";
return(Cal_str);
}

function DateChange(mode){
var theYear=parseInt(ShowYear.innerText);
var theMonth=parseInt(ShowMon.innerText);
if(mode){
theMonth++;
if(theMonth>=13){
theYear++;
theMonth=1;
}
}else{
theMonth--;
if(theMonth<=0){
theYear--;
theMonth=12;
}
}
ShowYear.innerText=theYear;
ShowMon.innerText=theMonth;
Cal_Tab.innerHTML=Calendar(theYear,theMonth-1);
}
function YearChange(){
var theYear;
theYear=prompt("Please input the year: (0 - 3000)",ShowYear.innerText);
if(theYear==null || theYear=="") return false;
theYear=parseInt(theYear);
theMon=parseInt(ShowMon.innerText);
if((theYear+"a")=="NaNa" || theYear>3000 || theYear<0){
alert("输入错误!");
return false;
}else{
ShowYear.innerText=theYear;
ShowMon.innerText=theMon;
Cal_Tab.innerHTML=Calendar(theYear,theMon-1);
}
setTimeout("LayerDate.style.visibility='visible'",10);
}
function MonChange(){
var theMon;
theMon=prompt("Please input the Month: (1 - 12)",ShowMon.innerText);
if(theMon==null || theMon=="") return false;
theMon=parseInt(theMon);
theYear=parseInt(ShowYear.innerText);
if((theMon+"a")=="NaNa" || theMon>12 || theMon<1){
alert("输入错误!");
return false;
}else{
ShowYear.innerText=theYear;
ShowMon.innerText=theMon;
Cal_Tab.innerHTML=Calendar(theYear,theMon-1);
}
setTimeout("LayerDate.style.visibility='visible'",10);
}
function showCalendar(){
event.cancelBubble = true;
LayerDate.style.top = event.srcElement.offsetTop + event.srcElement.offsetHeight + 2;
LayerDate.style.left = event.srcElement.offsetLeft - 150;
if(parseInt(LayerDate.style.left)<0) LayerDate.style.left = 0;
LayerDate.style.visibility = LayerDate.style.visibility=='hidden'?'visible':'hidden';
return false;
}
//-->
</script>
</head>
<body onClick="HideDate()">
<p align=center> </p>
<p align=center>
<input type=text id=selDate value="" style="width: 80px" readonly><input type=button value="q" style="FONT-SIZE: 7pt; FONT-FAMILY: Wingdings 3; width: 15pt" onClick="showCalendar()">
</p>
<div id="LayerDate" onClick="event.cancelBubble=true" style="position:absolute; width:300px; height:115px; z-index:1; visibility: hidden; BORDER: 1 solid black;">
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="40" align="center" bgcolor="#000000" nowrap> <input type="button" value="|" style="FONT-FAMILY: Wingdings 3;width: 20px" onClick="DateChange(false)"></td>
<td width="100%" align="center" bgcolor="#000000" style="color: white;FONT-WEIGHT: bold; CURSOR: default" nowrap><span id="ShowYear" onClick="YearChange()"></span> 年 <span id="ShowMon" onClick="MonChange()"></span> 月</td>
<td width="40" align="center" bgcolor="#000000" nowrap><input type="button" value="}" style="FONT-FAMILY: Wingdings 3;width: 20px" onClick="DateChange(true)"> </td>
</tr>
<tr>
<td colspan="3" align="center"> <span id="Cal_Tab"></span> </td>
</tr>
<tr>
<td height=30 colspan="3" valign="middle" style="cursor: default" onClick="Cal_Tab.innerHTML=Calendar(years,months-1);ShowYear.innerText=years;ShowMon.innerText=months"><image src=image/now.gif height=12>
<b>今天:
<script>document.write(years + "-" + months + "-" + days)</script>
</b> </td>
</tr>
</table>
</div>
<script language="JavaScript1.2">
ShowYear.innerText=years;
ShowMon.innerText=months;
Cal_Tab.innerHTML=Calendar(years,months-1);
ShowPlan(years,(months-1),days);
</script>
</body>
</html>
<think>好的,我现在需要帮助用户解决如何使用Python的Matplotlib库绘制景区景点价格分布折线图的问题。用户明确提到了示例、数据可视化、Python、matplotlib或其他库,所以需要给出具体的代码示例,并可能涉及其他库的建议。 首先,我需要回忆Matplotlib的基本用法,尤其是折线图的绘制步骤。根据用户提供的引用,特别是引用[2]和[4],用户之前可能已经看过一些基础教程,但需要针对景区价格分布的具体场景进行调整。因此,示例数据应该包含景点名称和对应的价格,并且可能需要处理多个景点的数据进行比较。 接下来,确定数据结构。用户可能需要将景点名称作为x轴,价格作为y轴。由于景点名称通常是字符串,需要确保Matplotlib能够正确处理x轴的标签。在引用[2]中,x轴是数值,但这里需要替换为字符串,所以可能需要使用plt.xticks来设置标签,或者直接传递字符串列表,但需要检查Matplotlib版本是否支持。 然后,考虑代码的结构。根据引用[2]和[4],基本步骤是导入库、准备数据、创建图表、设置标题和标签、显示或保存图表。需要将这些步骤应用到景区价格数据上。例如,准备两个列表,一个存储景点名称,另一个存储价格,然后使用plt.plot绘制折线图,并调整x轴的刻度标签。 另外,用户可能需要多个景点的价格对比,或者同一景点不同时间点的价格变化。但根据问题描述,用户提到的是分布图,可能更倾向于不同景点的价格比较。因此,示例数据应包含多个景点及其对应的价格。 同时,考虑是否需要使用其他库,比如Pandas来处理数据,或者Seaborn来美化图表。但用户主要询问的是Matplotlib或其他库,所以应该以Matplotlib为主,可能简要提及其他库作为备选。 还需要注意代码的完整性和可运行性。确保示例代码包含所有必要的导入和步骤,比如导入pyplot,准备数据,绘图,设置标签和标题,最后显示图表。此外,可能需要调整图表样式,比如线条颜色、标记点,或添加网格线,以提高可读性。 另外,用户的问题可能隐含对数据可视化的美观性要求,比如如何让折线图更清晰,如何处理大量数据点,或者如何添加注释。不过,用户当前的问题主要是如何实现基本的折线图,因此重点应放在基础实现上,再补充一些优化建议。 最后,生成相关问题,需要考虑用户可能的后续需求,比如如何处理动态数据、如何绘制多个折线进行比较、如何优化图表样式等。这些问题应围绕数据可视化的进阶应用展开,帮助用户深入探索。</think>根据您的需求,以下是用Python的Matplotlib库实现景区景点价格分布折线图的详细解决方案: ### 基础实现代码 ```python import matplotlib.pyplot as plt # 示例数据(景区名称和对应价格) scenic_spots = ['景点A', '景点B', '景点C', '景点D', '景点E'] prices = [120, 90, 150, 80, 200] # 创建画布和坐标轴 plt.figure(figsize=(10, 6), dpi=100) # 绘制折线图(蓝色实线带圆形标记) plt.plot(scenic_spots, prices, marker='o', # 添加数据点标记 linestyle='-', # 实线连接 color='#2E86C1', # 自定义颜色 linewidth=2) # 线宽 # 设置图表标题和坐标轴标签 plt.title('景区景点价格分布图', fontsize=14, pad=20) plt.xlabel('景区名称', fontsize=12) plt.ylabel('门票价格(元)', fontsize=12) # 设置刻度参数 plt.xticks(rotation=45) # x轴标签旋转45度 plt.grid(True, linestyle='--', alpha=0.7) # 添加虚线网格 # 自动调整布局并显示 plt.tight_layout() plt.show() ``` ### 功能扩展建议 1. **多景区对比**:使用不同颜色折线对比不同日期/季节价格 ```python # 添加对比数据 prices_holiday = [150, 120, 180, 100, 250] plt.plot(scenic_spots, prices, marker='o', label='平日价') plt.plot(scenic_spots, prices_holiday, marker='s', label='节假日价') plt.legend() ``` 2. **交互可视化**:使用Plotly实现可交互图表 ```python import plotly.express as px fig = px.line(x=scenic_spots, y=prices, labels={'x':'景区名称', 'y':'价格'}, title='景区价格分布(交互版)') fig.show() ``` 3. **样式优化**:添加数据标签 ```python for x, y in zip(scenic_spots, prices): plt.text(x, y+5, f'{y}元', ha='center', fontsize=10) ``` ### 数据准备建议 1. 推荐使用Pandas进行数据处理: ```python import pandas as pd df = pd.DataFrame({ '景区': ['景点A', '景点B', '景点C', '景点D', '景点E'], '价格': [120, 90, 150, 80, 200], '类型': ['自然景观', '人文景观', '自然景观', '主题公园', '自然景观'] }) # 按类型分组绘制 for type_name, group in df.groupby('类型'): plt.plot(group['景区'], group['价格'], marker='o', label=type_name) plt.legend() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值